|
@@ -0,0 +1,123 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace refill\hongxudagy;
|
|
|
|
+
|
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/hongxudagy/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['mer_id'] = config::MER_ID;
|
|
|
|
+ $params['mer_oid'] = $order_sn;
|
|
|
|
+ $params['product_face'] = $amount;
|
|
|
|
+ $params['product_num'] = 1;
|
|
|
|
+ $params['recharge_amount'] = $amount * config::PRICE;
|
|
|
|
+ $params['phone_no'] = $phone;
|
|
|
|
+ $params['notify_url'] = config::NOTIFY_URL;
|
|
|
|
+ $params['request_time'] = date("YmdHis");
|
|
|
|
+ $params['recharge_type'] = 0;
|
|
|
|
+ return $params;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
|
|
|
|
+ {
|
|
|
|
+ $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, 'GET', false, [], $net_errno);
|
|
|
|
+
|
|
|
|
+ if (empty($resp)) {
|
|
|
|
+ return [false, '网络错误', true];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
|
+ $resp = $this->xmlToArray($resp);
|
|
|
|
+ if (empty($resp)) {
|
|
|
|
+ return [false, '网络错误', true];
|
|
|
|
+ }else {
|
|
|
|
+ if ($resp['result'] == true && $resp['code'] == 100) {
|
|
|
|
+ return [true, $resp['data']['supply_id'], false];
|
|
|
|
+ } else {
|
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function query($refill_info)
|
|
|
|
+ {
|
|
|
|
+ $params['mer_oid'] = $refill_info['order_sn'];
|
|
|
|
+ $params['mer_id'] = config::MER_ID;
|
|
|
|
+ $params['tsp'] = date("YmdHis");
|
|
|
|
+ $content = "{$params['mer_oid']}{$params['mer_id']}{$params['tsp']}".config::KEY;
|
|
|
|
+ $params['sign'] = md5($content);
|
|
|
|
+
|
|
|
|
+ $resp = http_request(config::QUERY_URL, $params, 'GET', false, []);
|
|
|
|
+
|
|
|
|
+ if (empty($resp)) {
|
|
|
|
+ return [false, '网络错误'];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
|
+ $resp = $this->xmlToArray($resp);
|
|
|
|
+ if (empty($resp))
|
|
|
|
+ {
|
|
|
|
+ return [false, '网络错误'];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $code = $resp['code'];
|
|
|
|
+ if (in_array($code, [100, 101, 102, 103, 888])) {
|
|
|
|
+ $order_status = intval($resp['data']['order_status']);
|
|
|
|
+ if ($order_status === 0) {
|
|
|
|
+ $updata['official_sn'] = $resp['data']['cp_id'];
|
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $updata);
|
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
|
+ } elseif ($order_status === 3) {
|
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
|
+ } elseif (in_array($order_status, [1, 2])) {
|
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
|
+ } else {
|
|
|
|
+ return [false, $resp['msg']];
|
|
|
|
+ }
|
|
|
|
+ return [true, $order_state];
|
|
|
|
+ } elseif ($code === 258 && (time() - $refill_info['commit_time'] >= 600)) {
|
|
|
|
+ return [true, ORDER_STATE_NOEXIST];
|
|
|
|
+ } else {
|
|
|
|
+ return [false, $resp['msg']];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function sign($params)
|
|
|
|
+ {
|
|
|
|
+ $userid = config::MER_ID;
|
|
|
|
+ $key = config::KEY;
|
|
|
|
+ $content = "{$userid}{$params['mer_oid']}{$params['product_face']}{$params['product_num']}{$params['recharge_amount']}{$params['phone_no']}{$params['notify_url']}";
|
|
|
|
+ $content .= "{$params['request_time']}{$params['recharge_type']}{$key}";
|
|
|
|
+ return md5($content);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function xmlToArray($xml)
|
|
|
|
+ {
|
|
|
|
+ $replace_str = str_replace(' ','','encoding="gbk"');
|
|
|
|
+ $xml = mb_convert_encoding($xml,"UTF-8","gbk");
|
|
|
|
+ $xml = str_replace($replace_str, "encoding='utf-8'", $xml);
|
|
|
|
+ return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
|
|
|
+ }
|
|
|
|
+}
|