|
@@ -0,0 +1,108 @@
|
|
|
|
+<?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)
|
|
|
|
+ {
|
|
|
|
+ $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);
|
|
|
|
+
|
|
|
|
+ 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']];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function sign($data)
|
|
|
|
+ {
|
|
|
|
+ $str = "";
|
|
|
|
+ ksort($data);
|
|
|
|
+ foreach($data as $k => $v){
|
|
|
|
+ if($v){
|
|
|
|
+ $str .= $v;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return md5($str.config::KEY);
|
|
|
|
+ }
|
|
|
|
+}
|