123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace refill\xunao;
- require_once(BASE_HELPER_RAPI_PATH . '/xunao/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, int $card_type, string $order_sn)
- {
- $params['supplierId'] = config::USER_ID;
- $params['orderNo'] = $order_sn;
- $params['company'] = config::operator[$card_type];
- $params['amount'] = $amount;
- $params['phoneNo'] = $phone;
- $params['notifyUrl'] = config::NOTIFY_URL;
- return $params;
- }
- public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
- {
- $params = $this->req_params($card_no, $amount, $card_type, $params['order_sn']);
- $sign = $this->sign($params);
- $params['sign'] = $sign;
- $params = json_encode($params);
- $resp = http_post_data(config::ORDER_URL, $params , config::ExtHeaders , $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'] === 200) {
- return [true, $resp['data']['orderId'], false];
- } else {
- return [false, $resp['msg'], false];
- }
- }
- }
- public function query($refill_info)
- {
- $params['supplierId'] = config::USER_ID;
- $params['orderNo'] = $refill_info['order_sn'];
- $params['phoneNo'] = $refill_info['card_no'];
- $params['company'] = config::operator[$refill_info['card_type']];
- $params['sign'] = $this->sign($params);
- $params = json_encode($params);
- $resp = http_post_data(config::QUERY_URL, $params , config::ExtHeaders);
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- else
- {
- Log::record($resp, Log::DEBUG);
- $resp = json_decode($resp, true);
- if (empty($resp)) {
- return [false, '系统错误'];
- }
- elseif ($resp['code'] == 200)
- {
- $status = intval($resp['data']['status']);
- if ($status === 2) {
- $updata['official_sn'] = $resp['data']['ticketNo'];
- Model('refill_order')->edit($refill_info['order_id'], $updata);
- $order_state = ORDER_STATE_SUCCESS;
- } elseif ($status === 3) {
- $order_state = ORDER_STATE_CANCEL;
- } elseif (in_array($status, [0,1])) {
- $order_state = ORDER_STATE_SEND;
- } else {
- return [false, $resp['msg']];
- }
- return [true, $order_state];
- }
- else {
- return [false, $resp['msg']];
- }
- }
- }
- public function balance()
- {
- return [false, '暂无余额接口'];
- }
- private function sign($data)
- {
- $str = "";
- ksort($data);
- foreach($data as $k => $v){
- if($this->check_empty($v) === false){
- $str .= $v;
- }
- }
- return md5($str.config::KEY);
- }
- }
|