123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace refill\yifa;
- require_once(BASE_HELPER_RAPI_PATH . '/yifa/config.php');
- use refill;
- use Log;
- class RefillPhone extends refill\IRefillPhone
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- private function req_params(int $phone, int $amount ,string $order_sn)
- {
- $params['app_id'] = config::APP_ID;
- $params['nonce_str'] = strtoupper($this->createNoncestr());
- $params['timestamp'] = time();
- $params['order_sn'] = $order_sn;
- $params['phone'] = $phone;
- $params['amount'] = $amount;
- $params['notify_url'] = config::NOTIFY_URL;
- return $params;
- }
- public function add($card_no, $card_type,$amount,$params)
- {
- $order_sn = $params['order_sn'];
- $params = $this->req_params($card_no,$amount,$order_sn);
- $sign = $this->sign($params);
- $params['sign'] = $sign;
- $resp = http_request(config::ORDER_URL,$params,'POST',false,config::ExtHeaders);
- if (empty($resp)) {
- return [false,'系统错误',true];
- }
- $resp = json_decode($resp,true);
- if (empty($resp)) {
- return [false, '系统错误', true];
- } elseif ($resp['code'] == 10000 && $resp['message'] == 'success') {
- $result = $resp['result'];
- return [true, $result['order_sn'], false];
- } else {
- return [false, $resp['message'], false];
- }
- }
- public function query($refill_info)
- {
- }
- /**
- * 作用:产生随机字符串,不长于32位
- */
- public function createNoncestr( $length = 32 )
- {
- $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
- $str ="";
- for ( $i = 0; $i < $length; $i++ ) {
- $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);
- }
- return $str;
- }
- private function sign($params)
- {
- ksort($params);
- $app_secret = config::APP_SECRET;
- $content = $app_secret;
- foreach ($params as $key => $val)
- {
- if(empty($val)){
- continue;
- }
- $content .= "{$key}{$val}";
- }
- $content .= $app_secret;
- return strtoupper(md5($content));
- }
- }
|