xiaoyu 3 роки тому
батько
коміт
d5179a9709

+ 13 - 0
helper/refill/api/xyz/xinhengyangnew/API信息.txt

@@ -0,0 +1,13 @@
+账号:XHYyezi
+密码: 123456
+秘钥:7d1229a832a84d89824c01d201030331
+ID:200050
+登录地址:http://121.43.140.47:10186/plat/index
+
+话费下单地址:http://121.43.140.47:10186/plat/api/px/submit
+查询地址:http://121.43.140.47:10186/plat/api/px/query
+查询余额地址:http://121.43.140.47:10186/plat/api/px/balance
+
+测试ID:200000
+秘钥:2a7533687d974571a2051ad555bfd2f5
+对接文档地址:https://docs.qq.com/doc/DQUhRSEN1RHNLcHJN

+ 47 - 0
helper/refill/api/xyz/xinhengyangnew/RefillCallBack.php

@@ -0,0 +1,47 @@
+<?php
+namespace refill\xinhengyangnew;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xinhengyangnew/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $mchid = config::MCHID;
+        $key = config::KEY;
+        $content  = "mchid={$mchid}&orderid={$params['orderid']}&oid={$params['oid']}&status={$params['status']}&price={$params['price']}&key={$key}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['orderid'];
+        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false,false];
+        }
+
+        $order_id = $order_info['order_id'];
+        if ($status === 1) {
+            $data['official_sn'] = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === 2) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 142 - 0
helper/refill/api/xyz/xinhengyangnew/RefillPhone.php

@@ -0,0 +1,142 @@
+<?php
+
+namespace refill\xinhengyangnew;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xinhengyangnew/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)
+    {
+        $params['mchid'] = config::MCHID;
+        $params['orderid'] = $order_sn;
+        $params['phone'] = $phone;
+        $params['facevalue'] = $amount;
+        $params['isp'] = config::operator[$card_type];
+        $params['timestamp'] = $this->getMillisecond();
+        $params['backurl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $card_type, $amount, $input['order_sn']);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $params = json_encode($params);
+        $resp = http_post_data(config::ORDER_URL, $params , config::ExtHeaders, $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['status'] === 0) {
+                return [true, '', false];
+            } elseif ($resp['status'] === 999) {
+                $net_errno = "HTTP-{$resp['status']}";
+                return [false, $resp['msg'], true];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['mchid'] = config::MCHID;
+        $params['orderid'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "mchid={$params['mchid']}&orderid={$params['orderid']}&key={$key}";
+        $params['sign'] = md5($content);
+
+        $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, '系统错误'];
+            }
+            else {
+                $status = $resp['status'];
+                if ($status === 2) {
+                    $updata['official_sn'] = $resp['voucher'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 3) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 0) {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($status === 4 && (time() - $refill_info['commit_time'] >= 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['mchid'] = config::MCHID;
+        $key = config::KEY;
+        $content = "mchid={$params['mchid']}&key={$key}";
+        $params['sign'] = md5($content);
+        $params = json_encode($params);
+
+        $resp = http_post_data(config::BALANCE_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['status'] === 0) {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content  = "mchid={$params['mchid']}&orderid={$params['orderid']}&phone={$params['phone']}&facevalue={$params['facevalue']}&isp={$params['isp']}";
+        $content .= "&timestamp={$params['timestamp']}&key={$key}";
+        return md5($content);
+    }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function getMillisecond()
+    {
+        $cur = microtime (true);
+        return intval($cur * 1000);
+    }
+}

+ 22 - 0
helper/refill/api/xyz/xinhengyangnew/config.php

@@ -0,0 +1,22 @@
+<?php
+
+
+namespace refill\xinhengyangnew;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://121.43.140.47:10186/plat/api/px/submit';
+    const QUERY_URL = 'http://121.43.140.47:10186/plat/api/px/query';
+    const BALANCE_URL = 'http://121.43.140.47:10186/plat/api/px/balance';
+
+    const MCHID = '200050';
+    const KEY = '7d1229a832a84d89824c01d201030331';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_xinhengyangnew.php";
+    const operator = [
+        mtopcard\ChinaMobileCard => 1,
+        mtopcard\ChinaUnicomCard => 2,
+        mtopcard\ChinaTelecomCard => 3
+    ];
+    const ExtHeaders = ['Content-Type: application/json'];
+}

+ 2 - 2
helper/refill/api/xyz/yichangt_hf/RefillPhone.php

@@ -17,10 +17,10 @@ class RefillPhone extends refill\IRefillPhone
     private function req_params(int $card_no, string $order_sn, int $amount)
     {
         $params['appid'] = config::APP_ID;
-        $params['api_product'] = 'zshcz';
+        $params['api_product'] = 'dhcz';
+        $params['mobile'] = $card_no;
         $params['order'] = $order_sn;
         $params['cash'] = $amount;
-        $params['card'] = $card_no;
         $params['nonce'] = rand(100000,999999);
         $params['time'] = time();
         $params['notify'] = config::NOTIFY_URL;

+ 7 - 0
mobile/callback/refill_xinhengyangnew.php

@@ -0,0 +1,7 @@
+<?php
+
+$content = $_SERVER['post_content'];
+$inputs = json_decode($content,true) ?? [];
+refill\util::push_notify('xinhengyangnew',$inputs);
+
+echo ('ok');

+ 22 - 0
test/TestRefill.php

@@ -1713,6 +1713,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testXinhengyangnew()
+    {
+//        $provider = $this->getProvider('xinhengyangnew');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(13699279618, mtopcard\ChinaMobileCard, 30, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '90991642572014786398']);
+
+        $body = '{"mchid":"200050","msg":"充值失败","oid":"1000325764014","orderid":"90991642572014786398","price":28.62,"sign":"56db7e6a4748a74bd1fac1a1ad5e8d6d","status":2,"voucher":""}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('xinhengyangnew','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);
@@ -2392,6 +2406,14 @@ class TestRefill extends TestCase
 //        $resp = $provider->query(['order_sn' => '86471642400354465488']);
     }
 
+    public function testYichangt_hf()
+    {
+        $provider = $this->getProvider('yichangt_hf');
+//        $resp = $provider->balance();
+        $resp = $provider->add(1000111100021211884, mtopcard\SinopecCard, 50, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '86471642400354465488']);
+    }
+
     public function testYichangt_doubi()
     {
         $provider = $this->getProvider('yichangt_doubi');