|
@@ -0,0 +1,106 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill\amingjd;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_RAPI_PATH . '/amingjd/config.php');
|
|
|
+
|
|
|
+use refill;
|
|
|
+use Log;
|
|
|
+use mtopcard;
|
|
|
+
|
|
|
+class RefillPhone extends refill\IRefillPhone
|
|
|
+{
|
|
|
+ public function __construct($cfgs)
|
|
|
+ {
|
|
|
+ parent::__construct($cfgs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function req_params(int $phone, int $amount, string $order_sn)
|
|
|
+ {
|
|
|
+ $params['mchid'] = config::MCHID;
|
|
|
+ $params['tel'] = $phone;
|
|
|
+ $params['orderid'] = $order_sn;
|
|
|
+ $params['price'] = $amount;
|
|
|
+ $params['teltype'] = $this->phone_type($phone);
|
|
|
+ $params['timeout'] = 300;
|
|
|
+ $params['notify'] = config::NOTIFY_URL;
|
|
|
+ $params['time'] = time();
|
|
|
+ $params['rand'] = rand(100000,999999);
|
|
|
+
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add($card_no, $card_type, $amount, $params)
|
|
|
+ {
|
|
|
+ $params = $this->req_params($card_no, $amount, $params['order_sn']);
|
|
|
+ $sign = $this->sign($params);
|
|
|
+ $params['sign'] = $sign;
|
|
|
+
|
|
|
+ $resp = http_request(config::ORDER_URL, $params , 'POST' , false);
|
|
|
+ if ($resp === false) {
|
|
|
+ return [false, '系统错误', true];
|
|
|
+ } else {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if ($resp['code'] == 0) {
|
|
|
+ return [true, $resp['order_id'], false];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg'], false];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query($refill_info)
|
|
|
+ {
|
|
|
+ $params['orderid'] = $refill_info['order_sn'];
|
|
|
+ $params['mchid'] = config::MCHID;
|
|
|
+
|
|
|
+ $content = $params['mchid'] . $params['orderid'] . config::KEY;
|
|
|
+ $params['sign'] = md5($content);
|
|
|
+ $resp = http_request(config::QUERY_URL, $params , 'POST' , false);
|
|
|
+ if ($resp === false) {
|
|
|
+ return [false, '系统错误'];
|
|
|
+ } else {
|
|
|
+ Log::record($resp, Log::DEBUG);
|
|
|
+ $resp = json_decode($resp, true);
|
|
|
+ if ($resp['code'] == 100) {
|
|
|
+ $order_state = -1;
|
|
|
+ if ($resp['status'] == 3) {
|
|
|
+ $order_state = ORDER_STATE_SUCCESS;
|
|
|
+ $save['official_sn'] = strtolower($resp['out_order_id']) == 'null' ? '' : $resp['out_order_id'];
|
|
|
+ Model('refill_order')->edit($refill_info['order_id'], $save);
|
|
|
+ } elseif ($resp['status'] == 4) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ } elseif (in_array($resp['status'] , [1 , 2])) {
|
|
|
+ $order_state = ORDER_STATE_CANCEL;
|
|
|
+ }
|
|
|
+ if ($order_state == -1) {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ return [true, $order_state];
|
|
|
+ } else {
|
|
|
+ return [false, $resp['msg']];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sign($params)
|
|
|
+ {
|
|
|
+ $content = $params['mchid'] . $params['tel'] . $params['price'] . $params['orderid'] . $params['teltype'] . $params['timeout'] . $params['notify'];
|
|
|
+ $content .= $params['time'] . $params['rand'] . config::KEY;
|
|
|
+ return md5($content);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function phone_type($phone)
|
|
|
+ {
|
|
|
+ $card_type = mtopcard\card_type($phone);
|
|
|
+
|
|
|
+ if ($card_type == mtopcard\ChinaMobileCard) {
|
|
|
+ return 0;
|
|
|
+ } elseif ($card_type == mtopcard\ChinaUnicomCard) {
|
|
|
+ return 1;
|
|
|
+ } elseif ($card_type == mtopcard\ChinaTelecomCard) {
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|