123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace refill\feinimoshu_hf;
- require_once(BASE_HELPER_RAPI_PATH . '/feinimoshu_hf/config.php');
- use refill;
- use Log;
- class RefillPhone extends refill\IRefillPhone
- {
- public function __construct($cfgs)
- {
- parent::__construct($cfgs);
- }
- private function req_params(int $card_no, int $amount, string $order_sn)
- {
- $params['appid'] = config::APPID;
- $params['notify'] = config::NOTIFY_URL;
- $params['card'] = $card_no;
- $params['order'] = $order_sn;
- $params['cash'] = $amount;
- $params['proid'] = 10012;
- return $params;
- }
- public function add($card_no, $card_type,$amount,$input,&$net_errno = 0)
- {
- $order_sn = $input['order_sn'];
- $params = $this->req_params($card_no,$amount,$order_sn);
- $sign = $this->sign($params);
- $params['signature'] = $sign;
- $resp = http_request(config::ORDER_URL,$params,'GET',false,[],$net_errno);
- if (empty($resp)) {
- return [false,'系统错误',true];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误', true];
- } elseif ($resp['code'] == 1) {
- return [true, $resp['data']['order'], false];
- } else {
- return [false, $resp['info'], false];
- }
- }
- }
- public function query($refill_info)
- {
- $params['appid'] = config::APPID;
- $params['morder'] = $refill_info['order_sn'];
- $sign = $this->sign($params);
- $params['signature'] = $sign;
- $resp = http_request(config::QUERY_URL,$params);
- if (empty($resp)) {
- return [false,'系统错误'];
- }
- else
- {
- Log::record($resp,Log::DEBUG);
- $resp = json_decode($resp,true);
- if (empty($resp)) {
- return [false, '返回值错误'];
- }
- $code = intval($resp['code']);
- $status = intval($resp['data']['status']);
- if ($code != 1) {
- return [false, $resp['info']];
- } elseif ($status == 2) {
- $order_state = ORDER_STATE_SUCCESS;
- $data['official_sn'] = strtolower($params['vnum']) == 'null' ? '' : $params['vnum'];
- Model('refill_order')->edit($refill_info['order_id'], $data);
- } elseif ($status == 3) {
- $order_state = ORDER_STATE_CANCEL;
- } else {
- $order_state = ORDER_STATE_SEND;
- }
- return [true, $order_state];
- }
- }
- public function balance()
- {
- $params['appid'] = config::APPID;
- $sign = $this->sign($params);
- $params['signature'] = $sign;
- $resp = http_request(config::QUERY_URL,$params);
- if($resp === false) {
- }
- else {
- }
- }
- private function sign($input)
- {
- $key = config::APPKEY;
- $body = config::body($input);
- $body .= "&token={$key}";
- return strtolower(md5($body));
- }
- }
|