HARUHARU 4 years ago
parent
commit
3d89ab6682

+ 14 - 0
data/config/lingzh/refill.ini.php

@@ -131,6 +131,19 @@ $yibao_phone = ['name' => 'yibao', 'store_id' => 38,
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$amingyd_phone = ['name' => 'amingyd', 'store_id' => 39,
+    'amount' => [
+        30 => [['goods_id' => 45, 'price' => 28.5, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 45, 'price' => 28.8, 'quality' => 2, 'card_type' => 'chinamobile']],
+        50 => [['goods_id' => 46, 'price' => 47.5, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 46, 'price' => 48, 'quality' => 2, 'card_type' => 'chinamobile']],
+        100 => [['goods_id' => 47, 'price' => 95, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 47, 'price' => 96, 'quality' => 2, 'card_type' => 'chinamobile']],
+        200 => [['goods_id' => 48, 'price' => 190, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 48, 'price' => 192, 'quality' => 2, 'card_type' => 'chinamobile']],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
     ['name' => 'baizeyd', 'cfg' => $baizeyd, 'opened' => true, 'sort' => 1],
     ['name' => 'aming', 'cfg' => $aming_phone, 'opened' => true, 'sort' => 1],
@@ -138,5 +151,6 @@ $phone_providers = [
     ['name' => 'ruishun', 'cfg' => $ruishun_phone, 'opened' => true, 'sort' => 1],
     ['name' => 'wuchen', 'cfg' => $wuchen_phone, 'opened' => true, 'sort' => 1],
     ['name' => 'yibao', 'cfg' => $yibao_phone, 'opened' => true, 'sort' => 1],
+    ['name' => 'amingyd', 'cfg' => $amingyd_phone, 'opened' => true, 'sort' => 1],
     ];
 $config['phone_providers'] = $phone_providers;

+ 75 - 0
helper/refill/api/lingzh/amingyd/RefillCallBack.php

@@ -0,0 +1,75 @@
+<?php
+
+
+namespace refill\amingyd;
+
+require_once(BASE_HELPER_RAPI_PATH . '/amingyd/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;
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if (false === $this->check_empty($val) && "@" != substr($val, 0, 1)) {
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $content .= "appSecret=".config::AppSecret;
+
+        return strtoupper(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'];
+        
+        $data['official_sn'] = strtolower($params['operatorId']) == 'null' ? '' : $params['operatorId'];
+
+        if ($status === 3) {
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 2) {
+            return [$order_id, false, false,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+}

+ 96 - 0
helper/refill/api/lingzh/amingyd/RefillPhone.php

@@ -0,0 +1,96 @@
+<?php
+
+namespace refill\amingyd;
+
+require_once(BASE_HELPER_RAPI_PATH . '/amingyd/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['appKey'] = config::AppKey;
+        $params['phone'] = $phone;
+        $params['amount'] = intval($amount * 100);
+        $params['orderId'] = $order_sn;
+        $params['notifyUrl'] = config::NOTIFY_URL;
+
+        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;
+        $params = json_encode($params);
+        $resp = http_post_data(config::ORDER_URL, $params , config::ExtHeaders);
+        if ($resp === false) {
+            return [false, '系统错误', true];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp ,true);
+            if($resp['code'] == 'success') {
+                return [true, $resp['data'], false];
+            }
+            return [false , $resp['message'], false];
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['orderId'] = $refill_info['order_sn'];
+        $params['appKey'] = config::AppKey;
+        $params['sign'] = $this->sign($params);
+
+        $params = json_encode($params);
+        $resp = http_post_data(config::QUERY_URL, $params , config::ExtHeaders);
+        if ($resp === false) {
+            return [false, '系统错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+
+            if ($resp['code'] == 'success') {
+                $order_state = -1;
+                $data = $resp['data'];
+                if ($data['status'] == 3) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $save['official_sn'] = strtolower($data['operatorId']) == 'null' ? '' : $data['operatorId'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                } elseif ($data['status'] == 2) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($data['status'] , [0,1,4])) {
+                    $order_state = ORDER_STATE_SEND;
+                }
+                if ($order_state == -1) {
+                    return [false, $resp['message']];
+                }
+                return [true, $order_state];
+            } else {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if (false === $this->check_empty($val) && "@" != substr($val, 0, 1)) {
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $content .= "appSecret=".config::AppSecret;
+
+        return strtoupper(md5($content));
+    }
+}

+ 16 - 0
helper/refill/api/lingzh/amingyd/config.php

@@ -0,0 +1,16 @@
+<?php
+
+
+namespace refill\amingyd;
+
+
+class config
+{
+    const ORDER_URL = 'http://8.135.98.236:8080/morgan/boss/agent/preOrder';
+    const QUERY_URL = 'http://8.135.98.236:8080/morgan/boss/agent/query';
+
+    const AppKey = '40695059';
+    const AppSecret = 'FAQLV7PAEHLJPTUFZ06DSBIBRB77A568';
+    const NOTIFY_URL = "http://121.89.212.167/racc/callback/lingzh/amingyd.php";
+    const ExtHeaders = ['Content-Type: application/json;'];
+}

+ 4 - 1
helper/refill/api/lingzh/api.php

@@ -19,4 +19,7 @@ require_once(BASE_HELPER_RAPI_PATH . '/wuchen/RefillPhone.php');
 require_once(BASE_HELPER_RAPI_PATH . '/wuchen/RefillCallBack.php');
 
 require_once(BASE_HELPER_RAPI_PATH . '/yibao/RefillPhone.php');
-require_once(BASE_HELPER_RAPI_PATH . '/yibao/RefillCallBack.php');
+require_once(BASE_HELPER_RAPI_PATH . '/yibao/RefillCallBack.php');
+
+require_once(BASE_HELPER_RAPI_PATH . '/amingyd/RefillPhone.php');
+require_once(BASE_HELPER_RAPI_PATH . '/amingyd/RefillCallBack.php');