|
@@ -0,0 +1,132 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\fangxing;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/fangxing/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+use Log;
|
|
|
+use QueueClient;
|
|
|
+
|
|
|
+class RefillPhone extends refill\IRefillPhone
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(int $phone, int $amount, string $order_sn)
|
|
|
+ {
|
|
|
+ $params['appKey'] = config::APP_KEY;
|
|
|
+ $params['ts'] = date("YmdHis").$this->get_millisecond();
|
|
|
+ $params['phoneNo'] = $phone;
|
|
|
+ $params['prodCode'] = $amount;
|
|
|
+ $params['prodId'] = '1';
|
|
|
+ $params['range'] = '0';
|
|
|
+ $params['backUrl'] = config::NOTIFY_URL;
|
|
|
+ $params['transNo'] = $order_sn;
|
|
|
+
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
|
|
|
+ {
|
|
|
+ $order_id = $params['order_id'];
|
|
|
+ $params = $this->req_params($card_no, $amount, $params['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 = json_decode($resp, true);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误', true];
|
|
|
+ } elseif ($resp['respCode'] === '10001' || $resp['respCode'] === '10005') {
|
|
|
+ return [true, $resp['orderId'], false];
|
|
|
+ } elseif ($resp['respCode'] === '10003') {
|
|
|
+ QueueClient::async_push("QueryRefillState",['order_id' => $order_id],5);
|
|
|
+ return [true, $resp['orderId'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['respMsg'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['appKey'] = config::APP_KEY;
|
|
|
+ $params['ts'] = date("YmdHis").$this->get_millisecond();
|
|
|
+ $params['orderId'] = $refill_info['order_sn'];
|
|
|
+ $appSecret = config::APP_SECRET;
|
|
|
+ $content = "appSecret={$appSecret}&orderId={$params['orderId']}&ts={$params['ts']}";
|
|
|
+ $params['sign'] = strtoupper(md5($content));
|
|
|
+
|
|
|
+ $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, '系统错误'];
|
|
|
+ } elseif ($resp['respCode'] === '10003') {
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ } elseif ($resp['respCode'] === '10002') {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif ($resp['respCode'] === '10001') {
|
|
|
+ $order_state = ORDER_STATE_SEND;
|
|
|
+ } else {
|
|
|
+ return [false, $resp['respMsg']];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balance()
|
|
|
+ {
|
|
|
+ $params['appKey'] = config::APP_KEY;
|
|
|
+ $params['ts'] = date("YmdHis").$this->get_millisecond();
|
|
|
+ $appSecret = config::APP_SECRET;
|
|
|
+ $content = "appSecret={$appSecret}&ts={$params['ts']}";
|
|
|
+ $params['sign'] = strtoupper(md5($content));
|
|
|
+
|
|
|
+ $resp = http_request(config::BALANCE_URL, $params);
|
|
|
+
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if (empty($resp)) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ } elseif ($resp['respCode'] === '0000') {
|
|
|
+ return [true, $resp['balance']];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['respMsg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $appSecret = config::APP_SECRET;
|
|
|
+ $content = "appSecret={$appSecret}&backUrl={$params['backUrl']}&phoneNo={$params['phoneNo']}&prodCode={$params['prodCode']}&prodId={$params['prodId']}&transNo={$params['transNo']}&ts={$params['ts']}";
|
|
|
+ return strtoupper(md5($content));
|
|
|
+ }
|
|
|
+
|
|
|
+ private function get_millisecond()
|
|
|
+ {
|
|
|
+ list($usec, $sec) = explode(" ", microtime());
|
|
|
+ return round($usec*1000);
|
|
|
+ }
|
|
|
+}
|