Forráskód Böngészése

add 速回充天猫接口

stanley-king 4 éve
szülő
commit
2fc3e73018

+ 10 - 1
data/config/prod/refill.ini.php

@@ -8,7 +8,16 @@ $suhc_oil = ['name' => 'suhc', 'store_id' => 7, 'card_type' => ['sinopec'],
         2000 => ['goods_id' => 6294, 'price' => 1936]],
     'period' => ['start' => '8:30', 'end' => '22:30'], 'refill_type' => 'api'];
 
-$oil_providers = ['suhc' => $suhc_oil];
+$suhctm_oil = ['name' => 'suhctm', 'store_id' => 7, 'card_type' => ['sinopec'],
+    'amount' => [100 => ['goods_id' => 6290, 'price' => 96.8],
+        200 => ['goods_id' => 6291, 'price' => 193.6],
+        500 => ['goods_id' => 6292, 'price' => 484],
+        1000 => ['goods_id' => 6293, 'price' => 968],
+        2000 => ['goods_id' => 6294, 'price' => 1936]],
+    'period' => ['start' => '8:30', 'end' => '22:30'], 'refill_type' => 'api'];
+
+
+$oil_providers = ['suhc' => $suhc_oil, 'suhctm' => $suhctm_oil];
 $config['oil_providers'] = $oil_providers;
 
 

+ 18 - 0
data/model/merchant_query.model.php

@@ -0,0 +1,18 @@
+<?php
+
+defined('InShopNC') or exit('Access Invalid!');
+class merchant_queryModel extends Model
+{
+    public function __construct()
+    {
+        parent::__construct('merchant_query');
+    }
+
+    public function query_info($mchid,$mch_ordersn) {
+        return $this->where(['mchid' => $mchid,'mch_ordersn' => $mch_ordersn])->field('*')->find();
+    }
+
+    public function add_info($mchid,$mch_ordersn,$data) {
+        return $this->insert(['mchid' => $mchid,'mch_ordersn' => $mch_ordersn,'request' => $data]);
+    }
+}

+ 1 - 1
helper/fcgi_server.php

@@ -27,7 +27,7 @@ class fcgi_server
         static $exfiles = ['web_wxnotify.php',
             'wxnotify.php','pub_wxnotify.php','alipay_notify_url.php','dispatch_notify.php','kdniao_notify.php',
             'cmbpay_notify.php','cmbpay_sign.php','wxauthor.php','api/wxLogin/index.php','api/wxLogin/callback.php',
-            'signature.php','merchant_xyz.php',
+            'signature.php','merchant_proxy.php',
             'refill_suhc.php','refill_beixt.php','refill_bxtwt.php','refill_bjb.php','refill_xyz.php'
         ];
         $path = BASE_ROOT_PATH . '/mobile/';

+ 11 - 0
helper/rbridge/IBridge.php

@@ -0,0 +1,11 @@
+<?php
+
+
+namespace rbridge;
+
+
+interface IBridge
+{
+    public function add($params);
+    public function notify($params);
+}

+ 74 - 0
helper/rbridge/RBridgeFactory.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace rbridge;
+
+require_once(BASE_HELPER_PATH . '/rbridge/IBridge.php');
+require_once(BASE_HELPER_PATH . '/rbridge/shr/Bridge.php');
+require_once(BASE_HELPER_PATH . '/refill_proxy.php');
+
+use Exception;
+use Log;
+
+class RBridgeFactory
+{
+    private static $stInstance = null;
+
+    public static function instance()
+    {
+        if (self::$stInstance == null) {
+            self::$stInstance = new RBridgeFactory();
+        }
+        return self::$stInstance;
+    }
+
+    private $mMerchants;
+
+    private function __construct()
+    {
+        $this->mMerchants = [];
+    }
+
+    public function add($mch_name,$parmas)
+    {
+        $bridge = $this->find($mch_name);
+        if(is_null($bridge)) {
+            return false;
+        }
+
+        $ret = $bridge->add($parmas);
+        return $ret;
+    }
+
+    public function notify($mch_name,$parmas)
+    {
+
+    }
+
+    private function find($name)
+    {
+        try
+        {
+            if(array_key_exists($name,$this->mMerchants)) {
+                return $this->mMerchants[$name];
+            }
+
+            $class = "rbridge\\{$name}\\Bridge";
+            if(class_exists($class,false)) {
+                $merchant = new $class();
+                $this->mMerchants[$name] = $merchant;
+                return $merchant;
+            } else {
+                $error = "Error: class {$class} isn't exists!";
+                throw new Exception($error);
+            }
+        }
+        catch (Exception $ex)
+        {
+            Log::record($ex->getMessage(),Log::ERR);
+        }
+
+        return null;
+    }
+
+
+}

+ 101 - 0
helper/rbridge/shr/Bridge.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace rbridge\shr;
+require_once(BASE_HELPER_PATH . '/rbridge/shr/config.php');
+
+
+use rbridge\IBridge;
+use refill_proxy;
+
+class Bridge implements IBridge
+{
+    public function add($params)
+    {
+        if($this->verify($params) === false) {
+            return [false,"签名不成功"];
+        }
+
+        $action = $params['action'];
+        $chargeType = intval($params['chargeType']);
+
+        if($action != 'CZ') {
+            return [false,"不支持该业务"];
+        }
+
+        //业务类型
+        //0:话费 1:Q币 2:QQ会员 3:游戏
+        //4:水电气 5:流量 6:票务 7:固话 8:宽带 9:油卡
+        if($chargeType !== 0 && $chargeType !== 9) {
+            return false;
+        }
+
+        $input = ['mchid' => config::MCHID,
+            'cardno' => $params['chargeAcct'],
+            'amount' => $params['chargeCash'],
+            "act"=>"refill",
+            "op"=>"add",
+            'order_sn' => $params['chargeId'],
+            'notifyurl'=> config::MCH_NOTIFY_URL];
+
+        Model('merchant_query')->add_info(config::MCHID,$params['chargeId'],json_encode($params));
+
+        $proxy = new refill_proxy(config::MCH_KEY);
+        [$code,$msg] = $proxy->send(config::MCH_REQUST_URL,$input);
+
+        if($code) {
+
+        }
+        else {
+
+        }
+    }
+
+    private function retbody($code,$msg,$params)
+    {
+        //交易结果 0:未处理 1:充值成功 2:充值结果不确定 3:充值失败
+        if($code === false) {
+            $retCode = 3;
+            $retDetail = $msg;
+        } elseif ($code === 200) {
+            $retCode = 0;
+            $retDetail = '定单已接收';
+        } else {
+            $retCode = 3;
+            $retDetail = $msg;
+        }
+
+        $result = [
+            'action' => 'CZ',
+            'chargeId' => $params['chargeId'],
+            'retCode'  => $retCode,
+            'retDetail' => $retDetail,
+            'retRsn' => $params['retRsn']
+
+
+
+
+
+
+        ];
+
+    }
+
+    public function notify($params)
+    {
+
+    }
+
+    private function verify($params)
+    {
+        //md5(chargeId + chargeAcct + var1 + var2 + var3 + var4 + chargeCash + md5key)
+        $keys = ['chargeId','chargeAcct','var1','var2','var3','var4','chargeCash'];
+        $body = "";
+        foreach ($keys as $key) {
+            $body .= $params[$key] ?? "";
+        }
+        $body .= config::BridgeKey;
+        $sign = md5($body);
+
+        return $params['sign'] == $sign;
+    }
+}

+ 13 - 0
helper/rbridge/shr/config.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace rbridge\shr;
+
+class config
+{
+    const MCHID = 1093;
+    const MCH_KEY  = '210fe406954220f56085997d6a4c5b80';
+    const MCH_NOTIFY_URL = 'https://www.xyzshops.cn/mobile/merchant_proxy.php?mchname=shr';
+    const MCH_REQUST_URL = 'https://www.xyzshops.cn/mobile/index.php';
+
+    const BridgeKey = 'bff0378ea5ef0d5d';
+}

+ 10 - 4
helper/refill/RefillFactory.php

@@ -3,16 +3,22 @@
 
 namespace refill;
 
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
+
 require_once(BASE_HELPER_PATH . '/refill/IRefill.php');
 require_once(BASE_HELPER_PATH . '/refill/IRefillOil.php');
 require_once(BASE_HELPER_PATH . '/refill/IRefillPhone.php');
 require_once(BASE_HELPER_PATH . '/refill/IRefillCallBack.php');
-require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
+require_once(BASE_HELPER_PATH . '/refill/CalcMerchantPrice.php');
+
 
 require_once(BASE_HELPER_PATH . '/refill/suhc/RefillOil.php');
 require_once(BASE_HELPER_PATH . '/refill/suhc/RefillPhone.php');
 require_once(BASE_HELPER_PATH . '/refill/suhc/RefillCallBack.php');
-require_once(BASE_HELPER_PATH . '/refill/CalcMerchantPrice.php');
+
+require_once(BASE_HELPER_PATH . '/refill/suhctm/RefillOil.php');
+require_once(BASE_HELPER_PATH . '/refill/suhctm/RefillPhone.php');
+require_once(BASE_HELPER_PATH . '/refill/suhctm/RefillCallBack.php');
 
 require_once(BASE_HELPER_PATH . '/refill/beixt/RefillPhone.php');
 require_once(BASE_HELPER_PATH . '/refill/beixt/RefillCallBack.php');
@@ -31,9 +37,9 @@ use Exception;
 
 class RefillFactory
 {
-    static private $stInstance = null;
+    private static $stInstance = null;
 
-    static public function instance()
+    public static function instance()
     {
         if (self::$stInstance == null) {
             self::$stInstance = new RefillFactory();

+ 1 - 1
helper/refill/suhc/RefillPhone.php

@@ -1,7 +1,7 @@
 <?php
 
 
-namespace refill\suht;
+namespace refill\suhc;
 
 
 use refill\IRefillPhone;

+ 74 - 0
helper/refill/suhctm/RefillCallBack.php

@@ -0,0 +1,74 @@
+<?php
+
+
+namespace refill\suhctm;
+
+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 check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v) {
+            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urldecode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urldecode($v);
+                }
+                $i++;
+            }
+        }
+
+        $body .= "&key=" . config::KEY;
+        return md5($body);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['onlystr'];
+
+        $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 === 2) {
+            return [$order_id, true, false,true];
+        } else {
+            //速汇充反馈此时可以提交多次.
+            return [$order_id, false, true,true];
+        }
+    }
+}

+ 109 - 0
helper/refill/suhctm/RefillOil.php

@@ -0,0 +1,109 @@
+<?php
+
+
+namespace refill\suhctm;
+
+require_once(BASE_HELPER_PATH . '/refill/suhctm/config.php');
+
+use refill;
+use mtopcard;
+use Log;
+
+class RefillOil extends refill\IRefillOil
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(string $card_no,int $card_type,int $amount,array $other)
+    {
+        $params['cardno'] = $card_no;
+
+        if($card_type == mtopcard\PetroChinaCard) {
+            $params['cardtype'] = "PetroChina";
+        }
+        elseif($card_type == mtopcard\SinopecCard) {
+            $params['cardtype'] = "Sinoepc";
+        }
+        else {
+            Log::record("RefillOil req_params err params",Log::DEBUG);
+        }
+
+        $params['amt'] = $amount;
+        $params['onlystr'] = $other['order_sn'];
+        $params['notifyurl'] = config::NOTIFY_URL;
+        $params['orgid'] = config::ORGID;
+
+        return $params;
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            $content .= "{$key}={$val}&";
+        }
+        $content .= "key=".config::KEY;
+
+        return md5($content);
+    }
+
+    public function add($card_no,$card_type,$amount,$input)
+    {
+        $params = $this->req_params($card_no,$card_type,$amount,$input);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL,$params,'POST',false, config::ExtHeaders);
+        if($resp === false) {
+            return [false,'系统错误'];
+        }
+        else
+        {
+            Log::record($resp,Log::DEBUG);
+            $resp = json_decode($resp,true);
+            if($resp['state'] == 0) {
+                return [true,$resp['data']];
+            }
+            else {
+                return [false,$resp['msg']];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['batchid'] = $refill_info['ch_trade_no'];
+        $params['orgid'] = config::ORGID;
+        $params['cardno'] = $refill_info['card_no'];
+        $params['onlystr'] = $refill_info['order_sn'];
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_QUERY_URL,$params,'POST',false,config::ExtHeaders);
+        if($resp === false) {
+            return [false,'系统错误'];
+        }
+        else
+        {
+            Log::record($resp,Log::DEBUG);
+            $resp = json_decode($resp,true);
+            if($resp['state'] == 0) {
+                return [true,$resp['data']];
+            }
+            else {
+                return [false,$resp['msg']];
+            }
+        }
+    }
+
+    private function store()
+    {
+        $count = count(config::STOREIDS);
+        $pos = mt_rand(0,$count - 1);
+
+        return config::STOREIDS[$pos];
+    }
+}

+ 24 - 0
helper/refill/suhctm/RefillPhone.php

@@ -0,0 +1,24 @@
+<?php
+
+
+namespace refill\suhctm;
+
+
+use refill\IRefillPhone;
+
+class RefillPhone extends IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    public function add($card_no,$card_type,$amount,$input)
+    {
+        return [false,'No Implement'];
+    }
+    public function query($refill_info)
+    {
+        return [false,'No Implement'];
+    }
+}

+ 26 - 0
helper/refill/suhctm/config.php

@@ -0,0 +1,26 @@
+<?php
+
+
+namespace refill\suhctm;
+
+
+class config
+{
+    const ORDER_URL = 'http://jiayouka.5800cc.com/tmKaOrder/createKaOrder.html';
+    const ORDER_QUERY_URL = 'http://jiayouka.5800cc.com/tmKaOrder/queryOrder.html';
+    const KEY = '7yDCLS6S2KzSAJQOUc3vsa';
+    const ORGID = 1590993600;
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/refill_suhctm.php";
+    const STOREIDS = ['10280838',
+        '611127',
+        '10109062',
+        '10053330',
+        '10108936'
+//        '10114157',
+//        '10143029',
+//        '10109046',
+//        '10135551',
+//        '678278'
+        ];
+    const ExtHeaders = ['Content-Type: application/x-www-form-urlencoded' , 'Accept: application/json;charset=UTF-8'];
+}

+ 127 - 0
helper/refill_proxy.php

@@ -0,0 +1,127 @@
+<?php
+
+
+class refill_proxy
+{
+    private $mKey;
+
+    public function __construct($key)
+    {
+        $this->mKey = $key;
+    }
+
+    public function send($url,$params)
+    {
+        $body = $this->body($params);
+        $body .= "&key={$this->mKey}";
+        $params['sign'] = md5($body);
+
+        $resp = $this->http_request($url,$params,'POST');
+        if($resp === false) {
+            return [false,'网络错误'];
+        }
+
+        $resp = json_decode($resp,true);
+        $code = $resp['code'];
+        if($resp['code'] == 200) {
+            return [$code,'success'];
+        }
+        else {
+            return [$code,$resp['message']];
+        }
+    }
+
+    private function body($params)
+    {
+        ksort($params);
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v)
+        {
+            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
+            {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+        return $body;
+    }
+
+    private function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function http_request($url, $params = array(), $method = 'GET', $multi = false, $extheaders = array())
+    {
+        if (!function_exists('curl_init')) {
+            return false;
+        }
+
+        $method = strtoupper($method);
+        $ci = curl_init();
+        curl_setopt($ci, CURLOPT_USERAGENT, 'PHP-SDK OAuth2.0');
+        curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($ci, CURLOPT_HEADER, false);
+        curl_setopt($ci, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
+
+        $headers = (array) $extheaders;
+        switch ($method)
+        {
+            case 'POST':
+                curl_setopt($ci, CURLOPT_POST, TRUE);
+                if (!empty($params))
+                {
+                    if ($multi)
+                    {
+                        foreach ($multi as $key => $file) {
+                            $params[$key] = '@' . $file;
+                        }
+                        curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
+                        $headers[] = 'Expect: ';
+                    }
+                    else {
+                        curl_setopt($ci, CURLOPT_POSTFIELDS, http_build_query($params));
+                    }
+                }
+                break;
+            case 'DELETE':
+            case 'GET':
+                if($method == 'DELETE') {
+                    curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
+                }
+                if (!empty($params)) {
+                    $url = $url . (strpos($url, '?') ? '&' : '?') . (is_array($params) ? http_build_query($params) : $params);
+                }
+                break;
+        }
+        curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
+        curl_setopt($ci, CURLOPT_URL, $url);
+        if ($headers) {
+            curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
+        }
+
+        $response = curl_exec($ci);
+        if($response == false) {
+            $err = curl_error($ci);
+            Log::record("http_post_data err={$err}",Log::ERR);
+        }
+
+        curl_close($ci);
+
+        return $response;
+    }
+}

+ 10 - 0
mobile/bridge_shr.php

@@ -0,0 +1,10 @@
+<?php
+
+require_once(BASE_HELPER_PATH . '/rbridge/RBridgeFactory.php');
+
+$content = $_SERVER['post_content'];
+$input = json_decode($content,true);
+
+rbridge\RBridgeFactory::instance()->add('shr',$input);
+
+echo ('ok');

mobile/merchant_xyz.php → mobile/merchant_proxy.php


+ 8 - 0
mobile/refill_suhctm.php

@@ -0,0 +1,8 @@
+<?php
+
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+
+refill\RefillFactory::instance()->notify('suhctm',$_POST);
+
+echo ('SUCCESS');
+

+ 27 - 0
test/TestRBridge.php

@@ -0,0 +1,27 @@
+<?php
+use PHPUnit\Framework\TestCase;
+
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
+
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+require_once(BASE_HELPER_PATH . '/rbridge/RBridgeFactory.php');
+
+
+
+class TestRBridge extends TestCase
+{
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+    public function testSurAdd()
+    {
+        $input = '{"action":"CZ","chargeId":196,"chargeAcct":"13530017201","chargeCash":100.000,"chargeType":0,"amount":1,"faceValue":100.000,"var1":"","var2":"","var3":"","var4":"","productSn":0,"nbrArea":"广东省深圳-移动","cardSn":"","cardPassword":"","agentAcct":"","agentPass":"","cardId":0,"retRsn":"0","sign":"3c90ed55aa363a22cd86746f34eeedb0"}';
+        $params = json_decode($input,true);
+        rbridge\RBridgeFactory::instance()->add('shr',$params);
+    }
+}

+ 21 - 0
test/TestRefill.php

@@ -259,6 +259,26 @@ class TestRefill extends TestCase
         Log::record($resp,Log::DEBUG);
     }
 
+    public function testZFKJ()
+    {
+        //带签名参数:mchid=1090&act=refill&op=add&cardno=100112121212212133
+        //&amount=10&order_sn=PH2012261356569433&
+        //notifyurl=https%3A%2F%2Fqzcz.edusahoo.com.cn%2Findex%2Findex%2Fcallback
+        //&sign=4a3ac5f9706e64aa70c6cab0fc5839d3
+
+        $params = ['mchid' => 1090,
+            'cardno' => '100112121212212133',
+            'amount' => '10',
+            "act"=>"refill",
+            "op"=>"add",
+            'order_sn' => 'PH2012261356569433',
+            'notifyurl'=> 'https://qzcz.edusahoo.com.cn/index/index/callback'];
+
+        $resp = $this->send_md5(BASE_SITE_URL . '/mobile/index.php',$params);
+
+
+    }
+
     protected function check_empty($value)
     {
         if (!isset($value))
@@ -323,6 +343,7 @@ class TestRefill extends TestCase
     {
         $body = $this->body($params);
         $body .= "&key={$this->mKey}";
+//        $body .= "&key=ZhongFKJZhongFKJZhongFKJ";
         $params['sign'] = md5($body);
 
         $resp = http_request($url,$params,'POST');