xiaoyu 3 lat temu
rodzic
commit
29be2c1847

+ 7 - 0
data/config/win/refill.ini.php

@@ -2103,8 +2103,15 @@ $lingzhthird = ['name' => 'lingzhthird', 'store_id' => 52,'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$jumithird = ['name' => 'jumithird', 'store_id' => 111,'qualitys' => '1',
+    'amount' => [
+        100 => [['goods_id' => 6978, 'price' => 99, 'quality' => 1, 'card_type' => 'third']],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $third_providers = [
     ['name' => 'lingzhthird', 'cfg' => $lingzhthird],
+    ['name' => 'jumithird', 'cfg' => $jumithird],
 ];
 $config['third_providers'] = $third_providers;
 

+ 67 - 0
helper/refill/api/xyz/jumithird/RefillCallBack.php

@@ -0,0 +1,67 @@
+<?php
+namespace refill\jumithird;
+require_once(BASE_HELPER_RAPI_PATH . '/jumithird/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            $content .= "{$key}={$val}&";
+        }
+        $content .= "token=".config::Token;
+
+        return md5($content);
+    }
+
+    //[$order_id, $success, $can_try, $need_handle]
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['order_no'];
+        $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['official_sn']) == 'null' ? '' : $params['official_sn'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 3) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 156 - 0
helper/refill/api/xyz/jumithird/RefillPhone.php

@@ -0,0 +1,156 @@
+<?php
+
+namespace refill\jumithird;
+
+require_once(BASE_HELPER_RAPI_PATH . '/jumithird/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    public function goods($quality, int $amount, int $card_type, $regin_no, $other)
+    {
+        [$goods_id, $price] = parent::goods($quality, $amount, $card_type, $regin_no, $other);
+        if ($goods_id <= 0) return [0, 0];
+
+        $store_id = $this->mStoreID;
+        $pcode = $other['product_code'];
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProviderProduct($store_id, $goods_id, $pcode);
+        if (empty($product)) {
+            Log::record("cannot find provider's produce where name={$this->mName}, goods_id = {$goods_id} pcode={$pcode}", Log::ERR);
+            return [0, 0];
+        } else {
+            return [$goods_id, ncPriceFormat($product['channel_amount'])];
+        }
+    }
+
+    private function getProductCode($goods_id, $sys_pcode)
+    {
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProviderProduct(111, $goods_id, $sys_pcode);
+        if (empty($product)) {
+            return false;
+        } else {
+            return $product['channel_code'];
+        }
+    }
+
+    private function req_params(int $phone, int $amount, string $order_sn, string $product_code)
+    {
+        $params['mch_no'] = config::MCH_ID;
+        $params['order_no'] = $order_sn;
+        $params['product_id'] = $product_code;
+        $params['money'] = $amount;
+        $params['account'] = $phone;
+        $params['notify_url'] = config::NOTIFY_URL;
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params, &$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        $goods_id = intval($params['goods_id']);
+        $product_code = $this->getProductCode($goods_id, $params['product_code']);
+
+        $params = $this->req_params($card_no, $amount, $order_sn, $product_code);
+        $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['code'] === '0000') {
+                return [true, $resp['data']['channel_order_no'], false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['mch_no'] = config::MCH_ID;
+        $params['order_no'] = $refill_info['order_sn'];
+        $params['sign'] = $this->sign($params);
+        $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, '系统错误'];
+            } elseif ($resp['code'] == '0000') {
+                $status = intval($resp['data']['status']);
+                if ($status === 1) {
+                    $updata['official_sn'] = $resp['data']['official_sn'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 3) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($status, [0, 2])) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['msg']];
+                }
+                return [true, $order_state];
+            } else {
+                return [false, $resp['msg']];
+            }
+
+        }
+    }
+
+    public function balance()
+    {
+        $params['mch_no'] = config::MCH_ID;
+        $params['sign'] = $this->sign($params);
+        $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['code'] == '0000') {
+                return [true, $resp['data']['money']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val) {
+            $content .= "{$key}={$val}&";
+        }
+        $content .= "token=" . config::Token;
+
+        return md5($content);
+    }
+}

+ 10 - 0
helper/refill/api/xyz/jumithird/api.txt

@@ -0,0 +1,10 @@
+新系统登录地址https://sever.jumiit.com/admin
+账号:yezi
+密码:yezihuafei
+技术信息
+商户号:210303112631
+api-token:7e145747925c1619c341ab6d4f6a2e71
+api文档地址 https://www.showdoc.cc/1278445497608240
+api提单使用需要提供提单ip加白名单。
+话费面额50/100/200
+话费系列产品id请登录商户首页

+ 15 - 0
helper/refill/api/xyz/jumithird/config.php

@@ -0,0 +1,15 @@
+<?php
+namespace refill\jumithird;
+
+class config
+{
+    const ORDER_URL = 'https://sever.jumiit.com/api/mch-api/createOrder';
+    const QUERY_URL = 'https://sever.jumiit.com/api/mch-api/getOrderInfo';
+    const BALANCE_URL = 'https://sever.jumiit.com/api/mch-api/getBalance';
+
+    const MCH_ID = '210303112631';
+    const Token = '7e145747925c1619c341ab6d4f6a2e71';
+//    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_jumi.php";
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+    const ExtHeaders = ['Content-Type: application/json'];
+}

+ 18 - 0
test/TestRefill.php

@@ -738,6 +738,24 @@ class TestRefill extends TestCase
 //        $resp = $providers->notify($params);
     }
 
+    public function testJumiThird()
+    {
+        $providers = $this->getProvider('jumithird');
+//        $resp = $providers->balance();
+//        $resp = $providers->add(588073521, 7, 100, [
+//            'order_sn' => $this->make_sn(),
+//            'goods_id' => 6978,
+//            'product_code' => 'XYZ100747'
+//        ]);
+//        $resp = $providers->query(['order_sn' => '53151629791019902609']);
+
+//        $body = '{"order_no":"59251629777055495341","channel_order_no":"C2108241152003775025","status":3,"money":"100.00","cost_money":"97.00","mch_no":210303112631,"account":"588073521","official_sn":"","sign":"7d7b3e701865b54c8cf0d9e903fdf6bf"}';
+//        $params = json_decode($body, true);
+//        $providers = $this->getProvider('jumithird','RefillCallBack');
+//        $ret = $providers->verify($params);
+//        $resp = $providers->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $providers = new refill\amingjd\RefillPhone([]);