|
@@ -0,0 +1,188 @@
|
|
|
+<?php
|
|
|
+namespace refill\douxun_copy;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/douxun_copy/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 $card_type, int $amount, string $order_sn)
|
|
|
+ {
|
|
|
+ $head['custInteId'] = config::custInteId;
|
|
|
+ $head['orderId'] = $order_sn;
|
|
|
+ $head['orderType'] = 1;
|
|
|
+ $head['echo'] = rand(100000,999999);
|
|
|
+ $head['timestamp'] = date("YmdHis");
|
|
|
+ $head['version'] = 1;
|
|
|
+
|
|
|
+ $params['packCode'] = config::PRODUCT[$card_type][$amount];
|
|
|
+ $params['mobile'] = $phone;
|
|
|
+ $params['effectType'] = 1;
|
|
|
+ $params['mobileOper'] = config::operator[$card_type];
|
|
|
+ return [$head,$params];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params, &$net_errno = 0)
|
|
|
+ {
|
|
|
+ $order_sn = $params['order_sn'];
|
|
|
+ [$head,$params] = $this->req_params($card_no, $card_type, $amount, $order_sn);
|
|
|
+ $sign = $this->sign($head);
|
|
|
+ $head['chargeSign'] = $sign;
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'head' => $head,
|
|
|
+ 'body' => [
|
|
|
+ 'item' => $params
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $xmlData = $this->toXmlData($data);
|
|
|
+
|
|
|
+ $resp = http_post_data(config::ORDER_URL, $xmlData, config::ExtHeaders, $net_errno);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = refill\util::xmlToArray($resp);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ } elseif ($resp['result'] === '0000') {
|
|
|
+ return [true, '', false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['desc'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ if (time() - $refill_info['commit_time'] > 86400*30) {
|
|
|
+ return [false, '时效已过'];
|
|
|
+ }
|
|
|
+ $head['custInteId'] = config::custInteId;
|
|
|
+ $head['echo'] = rand(100000,999999);
|
|
|
+ $head['timestamp'] = date("YmdHis");
|
|
|
+ $head['version'] = 1;
|
|
|
+ $content = $head['custInteId'] . config::KEY . $head['echo'] . $head['timestamp'];
|
|
|
+ $head['chargeSign'] = base64_encode(md5($content, true));
|
|
|
+
|
|
|
+ $params['orderIds'] = $refill_info['order_sn'];
|
|
|
+ $data = [
|
|
|
+ 'head' => $head,
|
|
|
+ 'body' => [
|
|
|
+ 'item' => $params
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $xmlData = $this->toXmlData($data);
|
|
|
+ $resp = http_post_data(config::QUERY_URL, $xmlData, config::ExtHeaders);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = refill\util::xmlToArray($resp);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误'];
|
|
|
+ }
|
|
|
+ elseif ($resp['head']['result'] === '0000')
|
|
|
+ {
|
|
|
+ $item = $resp['body']['item'];
|
|
|
+ $status = $item['state'];
|
|
|
+
|
|
|
+ if ($status === '1') {
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ $updata['official_sn'] = $item['operatorNo'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
+ } elseif ($status === '2') {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif ($status === '0') {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } elseif ($status === '-1' && (time() - $refill_info['commit_time'] > 600)) {
|
|
|
+ $order_state = ORDER_STATE_NOEXIST;
|
|
|
+ } else {
|
|
|
+ return [false, $item['desc']];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $order_state];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return [false, $resp['head']['desc']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $head['custInteId'] = config::custInteId;
|
|
|
+ $head['echo'] = rand(100000,999999);
|
|
|
+ $head['timestamp'] = date("YmdHis");
|
|
|
+ $head['version'] = 1;
|
|
|
+
|
|
|
+ $content = $head['custInteId'] . config::KEY . $head['echo'] . $head['timestamp'];
|
|
|
+ $head['chargeSign'] = base64_encode(md5($content, true));
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'head' => $head,
|
|
|
+ ];
|
|
|
+ $xmlData = $this->toXmlData($data);
|
|
|
+ $resp = http_post_data(config::BALANCE_URL, $xmlData, config::ExtHeaders);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = refill\util::xmlToArray($resp);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '网络错误', true];
|
|
|
+ } elseif ($resp['result'] === '0000') {
|
|
|
+ return [true, $resp['balance'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['desc'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $content = $params['custInteId'] . $params['orderId'] . config::KEY. $params['echo'] . $params['timestamp'];
|
|
|
+ return base64_encode(md5($content, true));
|
|
|
+ }
|
|
|
+
|
|
|
+ private function toXmlData($data)
|
|
|
+ {
|
|
|
+ return $this->xml_encode($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function xml_encode($data, $encoding='utf-8') {
|
|
|
+ $xml = '<?xml version="1.0" encoding="' . $encoding . '"?>';
|
|
|
+ $xml .= '<request>';
|
|
|
+ $xml .= $this->data_to_xml($data);
|
|
|
+ $xml .= '</request>';
|
|
|
+ return $xml;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function data_to_xml($data) {
|
|
|
+
|
|
|
+ $xml = '';
|
|
|
+ foreach ($data as $key => $val) {
|
|
|
+ is_numeric($key) && $key = "item id=\"$key\"";
|
|
|
+ $xml .= "<$key>";
|
|
|
+ $xml .= ( is_array($val) || is_object($val)) ? $this->data_to_xml($val) : $val;
|
|
|
+ list($key, ) = explode(' ', $key);
|
|
|
+ $xml .= "</$key>";
|
|
|
+ }
|
|
|
+ return $xml;
|
|
|
+ }
|
|
|
+}
|