Procházet zdrojové kódy

对公和对私支付的对接

jace před 6 roky
rodič
revize
bd4dddfbfe

+ 5 - 1
normandcrm/crm/backend/models/forms/PayForm.php

@@ -30,6 +30,8 @@ class PayForm extends Model
 		12 =>'银联支付B',
         13 =>'银联支付C',
         14 =>'JD通道A',
+        16 =>'对私支付',
+        17 =>'对公支付',
     ]; 
     public static $payMethods = [
         'renren' => 1,
@@ -44,7 +46,9 @@ class PayForm extends Model
 		'yinliantiaozhuan'=>11,
 		'yinliantiaozhuan2'=>12,
 		'yinliantiaozhuan3'=>13,
-		'jiedeng'=>14,
+        'jiedeng'=>14,
+        'duisi'=>16,
+        'duigong'=>17,
 		
     ];
 

+ 12 - 0
normandcrm/crm/backend/modules/user/controllers/PayController.php

@@ -43,6 +43,18 @@ class PayController extends BaseController
             if ($data['payType'] == 14) {
                 $data['amount'] = 0.00;
             }
+
+            if ($data['payType'] == 16) {
+                $data['bankCode'] = isset($data['duisiBankCode']) ? trim($data['duisiBankCode']) : '';
+                $amout_back = rand(1,70);
+                $data['amount'] = sprintf("%.2f",$data['amount']) + $amout_back/100;
+            }
+            if ($data['payType'] == 17) {
+                $data['bankCode'] = isset($data['duigongBankCode']) ? trim($data['duigongBankCode']) : '';
+                $amout_back = rand(1,70);
+                $data['amount'] = sprintf("%.2f",$data['amount']) + $amout_back/100;
+            }
+
 			//echo "<pre>";
 			//var_dump($data);die;
 

+ 75 - 3
normandcrm/crm/backend/modules/user/views/bankdeposit/index.php

@@ -226,6 +226,54 @@ $this->title = '入金';
                                 <div class="col-sm-1"></div>
                             </div>
                         </div>
+
+
+
+                        <div id="duisi_bank_code" style="display: none">
+                            <br>
+                            <div class="row">
+                                <div class="col-sm-1"></div>
+                                <div class="col-sm-4">
+                                    <div class="input-group">
+                                       <span class="input-group-btn">
+                                           <button type="button" class="btn btn-primary"><i class="fa fa-dollar"></i>支付方式</button>
+                                       </span>
+                                        <select id="duisiBankCode" name="duisiBankCode" class="form-control">
+                                            <option value="USDT_PAY">USDT支付</option>
+                                        </select>
+                                    </div>
+                                </div>
+                                <div class="col-sm-4" style="text-align:center;">
+                                   <!-- <span style="line-height: 2.5;color:red">此通道单笔转账金额必须大于7500美元</span> -->
+                                </div>
+                                <div class="col-sm-1"></div>
+                            </div>
+                        </div>
+
+
+
+                        <div id="duigong_bank_code" style="display: none">
+                            <br>
+                            <div class="row">
+                                <div class="col-sm-1"></div>
+                                <div class="col-sm-4">
+                                    <div class="input-group">
+                                       <span class="input-group-btn">
+                                           <button type="button" class="btn btn-primary"><i class="fa fa-dollar"></i>支付方式</button>
+                                       </span>
+                                        <select id="duigongBankCode" name="duigongBankCode" class="form-control">
+                                            <option value="USDT_PAY">人民币支付</option>
+                                        </select>
+                                    </div>
+                                </div>
+                                <div class="col-sm-4" style="text-align:center;">
+                                   <!-- <span style="line-height: 2.5;color:red">此通道单笔转账金额必须大于7500美元</span> -->
+                                </div>
+                                <div class="col-sm-1"></div>
+                            </div>
+                        </div>
+                         
+
 						
 
                         <div id="otczhifu_bank_code" style="display: none">
@@ -325,11 +373,11 @@ $this->title = '入金';
            $('.guojiyinlian').css('display','none');
            $('.well').text('入金,1个工作日到账。');
         }
-		if(payMethod == 'otczhifu'){
+		if(payMethod == 'otczhifu' || payMethod == 'duisi'){
            var money = usd;
         }
         $('#cny').val(money);
-        $('#amount').html('¥' + money)
+        $('#amount').html('¥' + money);
     }
     var changeBank =  function () {
         var payMethod = $("#payMethod").val();
@@ -370,7 +418,7 @@ $this->title = '入金';
         }
 		
 		
-		 //otc支付
+		//otc支付
         if (payMethod == 'otczhifu') {
             $("#otczhifu_bank_code").attr("style", "display:block");
             $('#RMBcode').text('USDT');
@@ -382,6 +430,30 @@ $this->title = '入金';
 			$('.well').text('友情提示:银联入金,1个工作日到账。');
         }
 
+        //对私支付
+        if (payMethod == 'duisi') {
+            $("#duisi_bank_code").attr("style", "display:block");
+            $('#RMBcode').text('USDT');
+            $('.guojiyinlian').css('display','none');
+			$('.well').text('友情提示: 1个工作日到账。');
+        } else {
+            $("#duisi_bank_code").attr("style", "display:none");
+            $('#RMBcode').text('人民币');
+			$('.well').text('友情提示:银联入金,1个工作日到账。');
+        }
+
+
+         //对公支付
+        if (payMethod == 'duigong') {
+            $("#duigong_bank_code").attr("style", "display:block");
+            $('#RMBcode').text('人民币');
+            $('.guojiyinlian').css('display','none');
+            $('.well').text('友情提示:银联入金,1个工作日到账。');
+        } else {
+            $("#duigong_bank_code").attr("style", "display:none");
+			$('.well').text('友情提示:银联入金,1个工作日到账。');
+        }
+
     }
     changeBank()
     $("#payMethod").on("change", changeBank);

binární
normandcrm/crm/backend/web/ui/img/duisi.png


+ 6 - 0
normandcrm/service/common/pay/BasePayHandler.php

@@ -108,6 +108,12 @@ eot;
             case 15:
                 $handler = new \common\pay\eagle\PayHandler();
                 break;
+            case 16:
+                $handler = new \common\pay\duisi\PayHandler();
+                break;
+            case 17:
+                $handler = new \common\pay\duigong\PayHandler();
+                break;
             default:
                 $handler = null;
                 break;

+ 2 - 0
normandcrm/service/common/pay/PayForm.php

@@ -39,6 +39,8 @@ class PayForm extends Model
         13 =>'银联支付C',
         14 =>'JD通道A',
         15 =>'eagle',
+        16 =>'对私支付',
+        17 =>'对公支付',
     ];
 
     /**

+ 142 - 0
normandcrm/service/common/pay/duigong/PayHandler.php

@@ -0,0 +1,142 @@
+<?php
+
+namespace common\pay\duigong;
+
+use backend\models\Config;
+use backend\models\Deposit;
+use backend\models\SyncDesposit;
+use common\pay\BasePayHandler;
+use backend\models\PublicAccount;
+use Yii;
+use yii\helpers\VarDumper;
+
+class PayHandler extends BasePayHandler
+{
+    public $payUrl;
+    public $merId;
+
+    /**
+     * @inheritdoc  
+     */
+    public function init()
+    {
+        parent::init();
+        if ($this->payUrl == null) {
+            $this->payUrl ='';
+        }
+
+        if ($this->merId == null) {
+            $this->merId ='';
+        }
+
+    }
+
+    /**
+     * @param array $deposit 
+     * @param array $params
+     * @return string
+     */
+    public function outPay($deposit, $params = [])
+    {
+        $data = [];
+        $money = sprintf("%.2f",$deposit['rmb']);
+
+        $PublicAccount = new PublicAccount();
+        $result = $PublicAccount->getAccountConfig();
+        $result_account = $result['account'];     // 卡号
+        $result_name = $result['name'];           // 收款姓名
+        $result_bank = $result['bank'];           // 收款开户行
+        return PayHandler::createGetHtml($money,$result_account,$result_name,$result_bank);
+    }
+
+    /**
+     * @param array $data
+     * @return bool
+     */
+    public function handleNotify($data)
+    {
+   		
+        // Yii::warning('支付异步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
+        if (isset($data['sign']) && trim($data['sign']) !== '') {
+			
+            if (PayUtils::verify($data, $this->publicKey)) {
+                if ($data['status'] == '1') {
+					
+                    $merOrderId = trim($data['orderNo']);
+                    $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
+                    if ($reuslt['type'] != 1) {
+                        $res = Deposit::updateAll(['type' => 1], "order_sn = $merOrderId");
+                        $configData = Config::find()->asArray()->one();
+                        if ($configData['auto_deposit'] == 1 && $res) {
+                            $syncDespositModel = new SyncDesposit();
+                            $syncDespositModel->login = $reuslt['login'];
+                            $syncDespositModel->amount = $reuslt['amount'];
+                            $syncDespositModel->comment = 'Deposit';
+                            $syncDespositModel->memo = $merOrderId;               //存储入金表的订单id
+                            $syncDespositModel->type = 2;
+                            $syncDespositModel->in_time = time();
+                            $syncDespositModel->save();
+                        }
+                        return success;
+                    }
+                }
+            }
+
+        }
+        return false;
+    }
+
+    public function outNotify($success)
+    {
+        if ($success == true) {
+            return "success";
+        } else {
+			// 返回的数据格式
+            return "FAIL";
+        }
+    }
+
+    /**
+     * @param array $data
+     * @return bool
+     */
+    public function handleReturn($data)
+    {
+        //Yii::warning('支付同步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
+        if (isset($data['sign']) && trim($data['sign']) !== '') {
+
+            if (PayUtils::verify($data, $this->publicKey)) {
+                if ($data['status'] == '1') {
+                    $merOrderId = trim($data['orderNo']);
+                    $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
+                    if ($reuslt) {
+                        return success;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    public function outReturn($success)
+    {
+
+    }
+
+
+    // 生成html模板文件
+    public static function createGetHtml($money,$result_account,$result_name,$result_bank)
+    {
+        $html = <<<eot
+        <div style="border: 1px solid green;width:800px;height: 350px;margin:10% auto;text-align:left;border-radius:30px;padding-top:70px; ">
+        <p>请转账到如下账户</p>
+        <p>订单金额为:<span style="color:red;">{$money}</span></p>
+        <p>收款账号为:{$result_account}</p>
+        <p>收款姓名为:$result_name</p>
+        <p>收款开户行为:{$result_bank}</p>
+        </div>
+eot;
+
+        return $html;
+    }
+}

+ 57 - 0
normandcrm/service/common/pay/duigong/PayUtils.php

@@ -0,0 +1,57 @@
+<?php
+namespace common\pay\duigong;
+
+class PayUtils
+{
+
+
+    /** 
+     * @param array $data
+     * @return string 
+     */
+    public static function makeSign($data, $privateKey)
+    {
+        $str = "";
+        ksort($data);
+        foreach ($data as $key => $value) {
+            $str .= "{$value}";
+        }
+        $rsa = openssl_pkey_get_private(file_get_contents( $privateKey));              
+        if (empty($rsa))
+        {
+            echo "private key resource identifier False!";
+            return False;
+        }
+        openssl_sign($str, $sign, $rsa,OPENSSL_ALGO_MD5);
+        $sign = base64_encode($sign);
+        return $sign;
+    }
+
+
+    /**
+     * @param array $data
+     * @param $pubCert
+     * @return bool|int
+     */
+    public static function verify($data, $pubCert)
+    {
+        // 签名
+        if (!isset($data['sign']) || trim($data['sign']) === '') {
+            return false;
+        }
+		$sign = $data['sign'];
+        unset($data['sign']);
+		ksort($data);   
+		$temp =  '';
+		foreach($data as $key=>$value)
+		{
+			$temp .="{$value}";
+		}	
+        $pubKey = openssl_get_publickey(file_get_contents($pubCert));
+		return openssl_verify($temp, base64_decode($sign), $pubKey, OPENSSL_ALGO_MD5);
+   
+    }
+
+
+
+}

+ 133 - 0
normandcrm/service/common/pay/duisi/PayHandler.php

@@ -0,0 +1,133 @@
+<?php
+
+namespace common\pay\duisi;
+
+use backend\models\Config;
+use backend\models\Deposit;
+use backend\models\SyncDesposit;
+use common\pay\BasePayHandler;
+use Yii;
+use yii\helpers\VarDumper;
+
+class PayHandler extends BasePayHandler
+{
+    public $payUrl;
+    public $merId;
+
+    /**
+     * @inheritdoc  
+     */
+    public function init()
+    {
+        parent::init();
+        if ($this->payUrl == null) {
+            $this->payUrl ='';
+        }
+
+        if ($this->merId == null) {
+            $this->merId ='';
+        }
+
+    }
+
+    /**
+     * @param array $deposit 
+     * @param array $params
+     * @return string
+     */
+    public function outPay($deposit, $params = [])
+    {
+        $data = [];
+        $money = sprintf("%.2f",$deposit['amount']);
+        return PayHandler::createGetHtml($money);
+    }
+
+    /**
+     * @param array $data
+     * @return bool
+     */
+    public function handleNotify($data)
+    {
+   		
+        // Yii::warning('支付异步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
+        if (isset($data['sign']) && trim($data['sign']) !== '') {
+			
+            if (PayUtils::verify($data, $this->publicKey)) {
+                if ($data['status'] == '1') {
+					
+                    $merOrderId = trim($data['orderNo']);
+                    $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
+                    if ($reuslt['type'] != 1) {
+                        $res = Deposit::updateAll(['type' => 1], "order_sn = $merOrderId");
+                        $configData = Config::find()->asArray()->one();
+                        if ($configData['auto_deposit'] == 1 && $res) {
+                            $syncDespositModel = new SyncDesposit();
+                            $syncDespositModel->login = $reuslt['login'];
+                            $syncDespositModel->amount = $reuslt['amount'];
+                            $syncDespositModel->comment = 'Deposit';
+                            $syncDespositModel->memo = $merOrderId;               //存储入金表的订单id
+                            $syncDespositModel->type = 2;
+                            $syncDespositModel->in_time = time();
+                            $syncDespositModel->save();
+                        }
+                        return success;
+                    }
+                }
+            }
+
+        }
+        return false;
+    }
+
+    public function outNotify($success)
+    {
+        if ($success == true) {
+            return "success";
+        } else {
+			// 返回的数据格式
+            return "FAIL";
+        }
+    }
+
+    /**
+     * @param array $data
+     * @return bool
+     */
+    public function handleReturn($data)
+    {
+        //Yii::warning('支付同步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
+        if (isset($data['sign']) && trim($data['sign']) !== '') {
+
+            if (PayUtils::verify($data, $this->publicKey)) {
+                if ($data['status'] == '1') {
+                    $merOrderId = trim($data['orderNo']);
+                    $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
+                    if ($reuslt) {
+                        return success;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    public function outReturn($success)
+    {
+
+    }
+
+
+        // 生成html模板文件
+    public static function createGetHtml($money)
+    {
+        $html = <<<eot
+        <div style="border: 1px solid green;width:800px;height: 350px;margin:10% auto;text-align: center;border-radius:30px;padding-top:70px; ">
+        <p>请转账到如下账户</p>
+        <p>订单金额为:<span style="color:red;">{$money}</span></p>
+        <img src="/ui/img/duisi.png" style="width:250px;"/>
+        </div>
+eot;
+
+        return $html;
+    }
+}

+ 57 - 0
normandcrm/service/common/pay/duisi/PayUtils.php

@@ -0,0 +1,57 @@
+<?php
+namespace common\pay\duisi;
+
+class PayUtils
+{
+
+
+    /** 
+     * @param array $data
+     * @return string 
+     */
+    public static function makeSign($data, $privateKey)
+    {
+        $str = "";
+        ksort($data);
+        foreach ($data as $key => $value) {
+            $str .= "{$value}";
+        }
+        $rsa = openssl_pkey_get_private(file_get_contents( $privateKey));              
+        if (empty($rsa))
+        {
+            echo "private key resource identifier False!";
+            return False;
+        }
+        openssl_sign($str, $sign, $rsa,OPENSSL_ALGO_MD5);
+        $sign = base64_encode($sign);
+        return $sign;
+    }
+
+
+    /**
+     * @param array $data
+     * @param $pubCert
+     * @return bool|int
+     */
+    public static function verify($data, $pubCert)
+    {
+        // 签名
+        if (!isset($data['sign']) || trim($data['sign']) === '') {
+            return false;
+        }
+		$sign = $data['sign'];
+        unset($data['sign']);
+		ksort($data);   
+		$temp =  '';
+		foreach($data as $key=>$value)
+		{
+			$temp .="{$value}";
+		}	
+        $pubKey = openssl_get_publickey(file_get_contents($pubCert));
+		return openssl_verify($temp, base64_decode($sign), $pubKey, OPENSSL_ALGO_MD5);
+   
+    }
+
+
+
+}