yingzi há 1 ano atrás
pai
commit
e625267a1c

+ 33 - 51
app/api/controller/Pay.php

@@ -7,6 +7,7 @@ use app\BaseController;
 use app\model\api\PayTrade;
 use library\services\UtilService;
 use library\utils\WxpayV2 as wxpayApi;
+use library\utils\weixinPay as wxpayApiV3;
 use WeChatPay\Transformer;
 use app\lib\OrderLib;
 use think\Exception;
@@ -26,59 +27,40 @@ class Pay extends BaseController{
         }
         file_put_contents($logfile, $xmlData.PHP_EOL,FILE_APPEND | LOCK_EX);
         $wxpay = new wxpayApi();
+        //回调验签
         $res = $wxpay->notifyCheckSign($xmlData);
-        if(!$res){
+        if(!$res || empty($res["data"])){
             return false;
         }
-//        if($res["return_code"] && $res["return_code"]=""){
-//            return false;
-//        }
-        
-        
-        
-        
-        
-        
-//
-//        if(empty($post["event_type"]) || $post["event_type"] != "TRANSACTION.SUCCESS"){
-//            return false;
-//        }
-//        if(empty($post["resource_type"]) || $post["resource_type"]!="encrypt-resource"){
-//            return false;
-//        }
-//        if(empty($post["resource"])){
-//            return false;
-//        }
-//        $wxpay = new wxpayApi();
-//        $result = $wxpay->aesGcmDecrypt([
-//            "associated_data"=>$post["resource"]["associated_data"],
-//            "nonce"=>$post["resource"]["nonce"],
-//            "ciphertext"=>$post["resource"]["ciphertext"],
-//        ]);
-//        
-//        if(!$result){
-//            return false;
-//        }
-//        //商家内部订单号
-//        $out_trade_no   = $result["out_trade_no"];
-//        $res = $wxpay->searchOrder($out_trade_no);
-//        if(!$res){
-//            return false;
-//        }
-//        $data = json_decode($res,true);
-//        //支付成功
-//        if($data["trade_state"]=="SUCCESS"){
-//            $payDataInfo = [
-//                    'totalMoney' =>(empty($data["amount"]) || empty($data["amount"]["total"]))      ?"未返回":$data["amount"]["total"]/100,
-//                    'payMoney'   =>(empty($data["amount"]) || empty($data["amount"]["payer_total"]))?"未返回":$data["amount"]["payer_total"]/100,
-//                    'payTradeNo' =>empty($data["transaction_id"]) ? "未返回" : $data["transaction_id"],
-//                    'outTradeNo' =>empty($data["out_trade_no"])   ? "未返回" : $data["out_trade_no"],
-//                    "tradeStatus"=>empty($data["trade_state"])    ? "未返回" : $data["trade_state"],
-//                    "payTime"    =>empty($data["success_time"])   ? "未返回" : $data["success_time"],
-//            ];
-//            $pay_json = json_encode($payDataInfo);
-//            (new OrderLib)->orderPay($out_trade_no, $pay_json);
-//        }
+        $result=$res["data"];
+        //验证返回信息
+        if(empty($result["return_code"]) || $result["return_code"]!="SUCCESS"){
+            return false;
+        }
+        //验证支付信息
+        if(empty($result["result_code"]) || $result["result_code"]!="SUCCESS"){
+            return false;
+        }
+        //查询订单
+        $out_trade_no   = $result["out_trade_no"];
+        $data = $wxpay->searchOrderQuery($out_trade_no);
+        if(empty($data)){
+            return false;
+        }
+        //支付成功
+        if($data["trade_state"]=="SUCCESS"){
+            $payDataInfo = [
+                'totalMoney' =>empty($data["total_fee"])      ? "未返回" : $data["total_fee"]/100,
+                'payMoney'   =>empty($data["cash_fee"])       ? "未返回" : $data["cash_fee"]/100,
+                'payTradeNo' =>empty($data["transaction_id"]) ? "未返回" : $data["transaction_id"],
+                'outTradeNo' =>empty($data["out_trade_no"])   ? "未返回" : $data["out_trade_no"],
+                "tradeStatus"=>empty($data["trade_state"])    ? "未返回" : $data["trade_state"],
+                "payTime"    =>empty($data["time_end"])       ? "未返回" : $data["time_end"],
+                "attach"     =>empty($data["attach"])         ? "未返回" : $data["attach"],
+            ];
+            $pay_json = json_encode($payDataInfo);
+            (new OrderLib)->orderPay($out_trade_no, $pay_json);
+        }
     }
      /**
      * 微信支付V3异步反馈
@@ -103,7 +85,7 @@ class Pay extends BaseController{
         if(empty($post["resource"])){
             return false;
         }
-        $wxpay = new wxpayApi();
+        $wxpay = new wxpayApiV3();
         $result = $wxpay->aesGcmDecrypt([
             "associated_data"=>$post["resource"]["associated_data"],
             "nonce"=>$post["resource"]["nonce"],

+ 34 - 77
app/lib/OrderLib.php

@@ -15,12 +15,10 @@ namespace app\lib;
 
 use app\model\api\PayTrade;
 use app\model\api\Order;
-use app\model\api\ActivityOrder;
+use app\model\api\ShowTemplateOrder;
 use app\model\api\OrderInfo;
-use app\model\api\Goods;
 use app\model\api\User as UserModel;
 use app\model\api\UserDetail as UserDetailModel;
-use app\model\api\UserScoreDetail;
 use app\model\api\Sys as SysModel;
 
 use think\facade\Db;
@@ -46,27 +44,45 @@ class OrderLib
         if ($payTradeData['status'] == 1) {
             return false;
         }
+        $userData = (new UserModel)->where('uid', $payTradeData['uid'])->find();
+        if(empty($userData)){
+            return false;
+        }
         //处理支付成功
         PayTrade::beginTrans();
-        $userData = (new UserModel)->where('uid', $payTradeData['uid'])->find();
         try {
             (new PayTrade)->where('id', $payTradeData['id'])->update(['status' => 1, 'pay_time' => time(),'pay_json' => $payDataInfo]);
-            if($payTradeData['type']=="activity"){
-                //活动报名
-                (new ActivityOrder)->where("id",$payTradeData['o_id'])->update(['status' => 1, 'pay_time' => time()]);
+            //购买模板
+            if($payTradeData["type"]=="temp"){
+                $tempOrderData = (new ShowTemplateOrder)->where("id",$payTradeData['o_id'])->find();
+                if(empty($tempOrderData)){
+                    PayTrade::rollbackTrans();
+                    return false;
+                }
+                (new ShowTemplateOrder)->where("id",$payTradeData['o_id'])->update(['status' => 1, 'pay_time' => time()]);
+                //验证用户是否已经购买过当前模板
+                $count = (new UserShowTemplate)->where("uid",$userData['uid'])->where("show_template_id",$tempOrderData["show_template_id"])->count();
+                if($count<=0){
+                    (new UserShowTemplate)->insert([
+                        "uid"              => $tempOrderData["uid"],
+                        "show_template_id" => $tempOrderData["show_template_id"],
+                        "start_time"       => time(),
+                        "end_time"         => time()+100*365*24*60*60,//100年
+                        "is_default"       => 0,
+                    ]);
+                }
+                //添加消费记录
+                if(in_array($payTradeData["pay_type"],["alipay","wxpay"])){
+                    (new UserDetailModel)->consumeLog($payTradeData['uid'],$payTradeData["money"],"show_temp_buy","购买名片模板");
+                }
                 PayTrade::commitTrans();
                 return true;
-            }else{
-                //商城下单
-                (new Order)->where("id",$payTradeData['o_id'])->update(['status' => 1, 'pay_time' => time()]);
             }
-            //商城下单普通商品增加积分
-            if ($payTradeData['type'] == 'pro') {
-                $json = unserialize($payTradeData['d_json']);
-                //添加购买用户的积分
-                if($json['give_score']>0){
-                    (new UserScoreDetail)->incomeScore($payTradeData['uid'], $json['give_score'], $payOn,"income_score",["o_id"=>$payTradeData['o_id']]);
-                }
+            //商城订单
+            if($payTradeData["type"]=="shop"){
+                (new Order)->where("id",$payTradeData['o_id'])->update(['status' => 1, 'pay_time' => time()]);
+                PayTrade::commitTrans();
+                return true;
             }
             PayTrade::commitTrans();
         } catch (DbException $dbException) {
@@ -77,66 +93,7 @@ class OrderLib
         if($payTradeData["pay_type"]=="system"){
             return true;
         }
-        //判断普通商品购买如果商品已被买断则在此处计算收益
-        $memData = $userData;
-        $orderData = (new Order)->where("id",$payTradeData['o_id'])->find();
-        $orderInfoData=null;
-        $proData=null;
-        if(!empty($orderData)){
-            $orderInfoData = (new OrderInfo)->where("o_id",$orderData['id'])->find()->toArray();
-        }
-        if(!empty($orderInfoData)){
-            $proData = (new Goods)->where("id",$orderInfoData["p_id"])->find();
-        }
-        //ip买断
-        if(!empty($proData) && $orderData["is_ip_buy"]==1 && empty($proData["uid"]) && $proData["is_ip"]==1){
-            (new Goods)->where("id",$proData["id"])->update(["uid"=>$memData["uid"],"uip"=>$memData["uip"]]);
-        }
-        
-//        return true;//暂时关闭分成
-        
-        //系统信息
-        $sysData = (new SysModel)->where("id",1)->find();
-        if($orderData["is_ip_buy"]==0){
-            //上级用户
-            if($memData["parent_uid"]>0){
-                //一级用户
-                $parentData = (new UserModel)->where("uid",$memData["parent_uid"])->where("status",1)->find();
-                if(!empty($parentData) && $sysData['tree_income_per']>0 && $sysData['tree_income_per']<=100){
-                    $treepermono = "推广用户购买商品获得分成";//分成内容
-                    $treePerMoney = $payTradeData["money"]*((int)$sysData['tree_income_per']/100);//分成收益金额
-                    if($treePerMoney>0){
-                        // return true;//暂时关闭分成
-                        (new UserDetailModel)->goodsIncome($memData["parent_uid"],$treePerMoney,"tree_per_income",$treepermono,["cash_uid"=>$memData["uid"],"p_id"=>$proData["id"],"o_id"=>$orderData["id"]]);
-                    }
-                }
-                //二级用户
-                if(!empty($parentData) && $parentData["parent_uid"] > 0 && $sysData['tree_income_per_two']>0 && $sysData['tree_income_per_two']<=100){
-                    $treepermonoTwo = "二级推广用户购买商品获得分成";//分成内容
-                    $treePerMoneyTwo = $payTradeData["money"]*((int)$sysData['tree_income_per_two']/100);//分成收益金额
-                    if($treePerMoneyTwo>0){
-                        // return true;//暂时关闭分成
-                        (new UserDetailModel)->goodsIncome($parentData["parent_uid"],$treePerMoneyTwo,"tree_per_income",$treepermonoTwo,["cash_uid"=>$memData["uid"],"p_id"=>$proData["id"],"o_id"=>$orderData["id"]]);
-                    }
-                }
-            }
-        }
-        //普通商品购买计算分成
-        if(!empty($proData) && $orderData["is_ip_buy"]==0 && !empty($proData["uid"]) && $proData["is_ip"]==1){
-            
-//            $sysPer=$sysData['ip_income_per'];//分成比例,后台设置
-            $sysPer=$proData['ip_income_per'];//如果是单个商品则用这条
-            if($sysPer<=0 || $sysPer>100){
-                return true;
-            }
-            $money = $payTradeData["money"];//支付金额
-            $permono = "用户购买商品获得分成";//分成内容
-            $perMoney = $money*((int)$sysPer/100);//分成收益金额
-            //增加用户收益
-            if($perMoney>0){
-                (new UserDetailModel)->goodsIncome($proData["uid"],$perMoney,"per_income",$permono,["cash_uid"=>$memData["uid"],"p_id"=>$proData["id"],"o_id"=>$orderData["id"]]);
-            }
-        }
+
         return true;
     }
 }

+ 28 - 43
app/model/api/UserDetail.php

@@ -14,14 +14,36 @@ use app\model\api\User as UserModel;
 class UserDetail extends BaseModel
 {
     private $config = [
-        'admin_add'          => ["code" => "后台补加余额",     "content" => "后台补加余额:{money}。"],
-        'admin_cut'          => ["code" => "后台补扣余额",     "content" => "后台补扣余额:{money}。"],
-        'tx_apply'           => ['code' => "提现余额",         "content" => "您发起提现,扣除余额:{money}。"],
-        'tx_refund'          => ['code' => "提现失败",         "content" => "提现失败,返还余额:{money}。"],
-        'per_income'         => ['code' => "商城购买分成",     "content" => "{mono} ,商品购买分成获得:{money}。"],
-        'tree_per_income'    => ['code' => "推广用户购买分成", "content" => "{mono} ,推广用户购买分成获得:{money}。"],
+        'admin_add'       => ["code" => "后台补加余额",     "content" => "后台补加余额:{money}。"],
+        'admin_cut'       => ["code" => "后台补扣余额",     "content" => "后台补扣余额:{money}。"],
+        'tx_apply'        => ['code' => "提现余额",        "content" => "您发起提现,扣除余额:{money}。"],
+        'tx_refund'       => ['code' => "提现失败",        "content" => "提现失败,返还余额:{money}。"],
+        'show_temp_buy'   => ['code' => "购买皮肤模板消费",  "content" => "{mono},用户消费:{money}。"],
         
     ];
+    /**
+     * 消费记录[不影响余额进出]
+     * @param type $uid
+     * @param type $money
+     * @param type $code
+     * @param type $mono
+     * @return bool
+     */
+    public function consumeLog($uid, $money,$code,$mono=""){
+        $money = bcadd((string)0, (string)$money, 2);
+        $post['uid']      = $uid;
+        $post['into']     = 0;//消费现金不影响余额进出
+        $post['code']     = $code;
+        $post['title']    = $this->config[$code]['code'];
+        $post['content']  = $this->TplParam($this->config[$code]['content'],compact('money','mono'));
+        $post['type']     = -1;
+        $post['money']    = (float)(new UserModel)->where('uid', $uid)->value('money');
+        $post['time']     = time();
+        $post['consume']  = floatval($money);//消费现金金额
+        $this->insert($post);
+        return true;
+    }
+    
     /**
      * 后台充值余额
      * @param $uid
@@ -146,43 +168,6 @@ class UserDetail extends BaseModel
             return false;
         }
     }
-
-    /**
-     * 购买获得收益
-     * @param type $uid
-     * @param type $money
-     * @param type $mono
-     * @param type $parms
-     */
-    public function goodsIncome($uid,$money,$code,$mono="",$parms=[]){
-        $money = num_min_format($money,2);
-        $post['uid']      = $uid;
-        $post['into']     = floatval($money);
-        $post['code']     = $code;
-        $post['title']    = $this->config[$code]['code'];
-        $post['content']  = $this->TplParam($this->config[$code]['content'],compact('money','mono'));
-        $post['type']     = 1;//收入为1,支出为-1
-        $post['money']    = (float)(new UserModel)->where('uid', $uid)->value('money') + floatval($money);//余额
-        $post['time']     = time();
-        $post['tx_id']    = 0;
-        $post['cash_uid'] = empty($parms["cash_uid"]) ? 0 : $parms["cash_uid"];
-        $post['p_id'] = empty($parms["p_id"]) ? 0 : $parms["p_id"];
-        $post['o_id'] = empty($parms["o_id"]) ? 0 : $parms["o_id"];
-        $this->insert($post);
-        //买断者收益
-        $perMoney = 0;
-        if(in_array($code,["per_income"])){
-            $perMoney = floatval($money);
-        }
-        $bool = Db::name("user")->where('uid', $uid)->inc('money', floatval($money))->inc('money_in', $perMoney)->update();
-        if ($bool > 0) {
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    
     /**
      * 转义的模板信息
      */

+ 0 - 424
library/utils/qnWxPay.php

@@ -1,424 +0,0 @@
-<?php
-/**
- * 微信支付
- * Created by PhpStorm.
- * User: phperstar
- * Date: 2019/11/28
- * Time: 2:12 PM
- */
-namespace Util\WeiXin;
-
-
-class QnWxPay
-{
-    /**
-     * 小程序 appId
-     * @var string $appid
-     */
-    private $appid;
-    /**
-     * 商户号
-     * @var string $mch_id
-     */
-    private $mch_id;
-
-    /**
-     * 商户支付密钥
-     */
-    private $partnerKey;
-
-    /**
-     * 微信支付异步通知地址
-     */
-    private $notifyUrl = PAY_NOTIFY_URL.'/common/WeiXinPayNotify/notify';
-
-    /**
-     * 公共的接口请求地址
-     * @var string
-     */
-    private $apiUrl = 'https://api.mch.weixin.qq.com/pay/';
-
-    /**
-     * 基础得请求地址
-     */
-     private $baseUrl = 'https://api.mch.weixin.qq.com/';
-     
-     
-     private $config;
-
-    /**
-     * Pay constructor.
-     * @param string $appid
-     * @param $mch_id
-     * @param $partnerKey
-     */
-    public function __construct($appid='', $mch_id, $partnerKey)
-    {
-        $this->appid = $appid;
-        $this->mch_id = $mch_id;
-        $this->partnerKey = $partnerKey;
-        if(empty($config)) $config = config('wxpay');
-        $this->config = $config;
-    }
-    
-    public function wxmpPay($post=[]){
-        $url = $this->apiUrl.'unifiedorder';
-        $params = [
-            'appid'            => $this->config["APPID"], // 小程序ID/微信开放平台审核通过的应用APPID
-            'mch_id'           => $this->config["MCHID"], // 商户号
-            'nonce_str'        => md5(md5(time().randString(10))), // 32位随机字符串
-            'out_trade_no'     => $post["out_trade_no"], // 商户订单号
-            'total_fee'        => (int)(floatval($post["total"])*100), // 订单总金额,单位分
-            'spbill_create_ip' => empty($post["payer_client_ip"])?"127.0.0.1":$post["payer_client_ip"], // 终端ip
-            'trade_type'       => "JSAPI", // 交易类型
-            'notify_url'       => $this->config["NOTIFY_URL"], // 通知地址
-            'body'             => empty($post["body"])  ?"微信小程序支付":$post["body"],
-            'attach'           => empty($post["attach"])?"微信小程序支付":$post["attach"],
-            'openid'           => $post["openid"],
-        ];
-        $params["sign"] = self::getSign($params);
-//        $post_xml = $this->arrayToWeiXinXml($params);
-        $curl_content = request($url, $post_xml);
-    }
-
-    /**
-     * 统一下单接口
-     */
-    public function unifiedorder($orderNo, $total_fee, $ip, $source, $shopName, $openid = '', $attach = '')
-    {
-        $url = $this->apiUrl.'unifiedorder';
-
-        switch ($source){
-            case 'H5':
-                $trade_type = 'MWEB';
-                break;
-            case 'APP':
-                $trade_type = 'APP';
-                break;
-            default:
-                $trade_type = 'JSAPI';
-                break;
-        }
-
-        $params = [
-            'appid'  => $this->appid, // 小程序ID/微信开放平台审核通过的应用APPID
-            'mch_id' => $this->mch_id, // 商户号
-            'nonce_str' => md5(md5(time().'qianniao.vip')), // 32位随机字符串
-            'out_trade_no' => $orderNo, // 商户订单号
-            'total_fee'  => yuanToFen($total_fee), // 订单总金额,单位分
-            'spbill_create_ip' => $ip, // 终端ip
-            'trade_type' => $trade_type, // 交易类型
-            'notify_url' => $this->notifyUrl, // 通知地址
-            'body'  => $shopName.'-'.'线上商城',
-            'attach' => $attach, // 附加数据
-        ];
-        if($trade_type == 'JSAPI'){
-            $params['openid'] = $openid;
-        }
-
-        $params['sign'] = self::getSign($params);
-        $post_xml = $this->arrayToWeiXinXml($params);
-        $curl_content = request($url, $post_xml);
-
-        $result = $this->commonResult($curl_content);
-        if(!$result->isSuccess()){
-            return ResultWrapper::fail($result->getData(), $result->getErrorCode());
-        }
-        $response_content = $result->getData();
-
-        //获取统一下单返回的id
-        $prepay_id = $response_content['prepay_id'];
-
-        // H5支付返回的支付跳转链接
-        $mweb_url = isset($response_content['mweb_url']) ? $response_content['mweb_url'] : '';
-
-        switch ($source){
-            case 'byteDanceH5':
-                $payParams = $mweb_url;  // 字节跳动小程序调用微信H5支付获取支付链接
-                break;
-            case 'H5':
-                $payParams =  self::payment($prepay_id);
-                break;
-            case 'APP':
-                $payParams =  self::payment($prepay_id);
-                break;
-            default:
-                $payParams =  self::paymentToMinprogram($prepay_id);
-                break;
-        }
-
-        return ResultWrapper::success($payParams);
-    }
-
-
-    /**
-     * 小程序调起支付用到的参数
-     * 官方接口地址: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=3
-     */
-    public function paymentToMinprogram($prepay_id)
-    {
-        unset($params);
-        $params = [
-            'appId' => $this->appid, // 小程序ID
-            'timeStamp' => (string)time(), //时间戳
-            'nonceStr' => md5(md5(time().'qianniao.vip')), //32位随机字符串
-            'package'  => 'prepay_id='.$prepay_id, // 数据包
-            'signType' => 'MD5', // 签名方式
-        ];
-        $params['paySign'] = self::getSign($params);
-        return $params;
-    }
-
-    /**
-     * 调起支付用到的参数
-     * 官方接口地址: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_12
-     * @param $prepay_id
-     */
-    public function payment($prepay_id)
-    {
-        unset($parm);
-        $parm = array(
-            'appid' => $this->appid,
-            'partnerid' => $this->mch_id,
-            'timestamp' => (string)time(), //时间戳
-            'noncestr' => md5(md5(time().'qianniao.vip')), //32位随机字符串
-            'prepayid' => $prepay_id, //统一下单接口返回的prepay_id 参数值
-            'package' => 'Sign=WXPay',
-        );
-        $parm['sign'] = self::getSign($parm);
-        return $parm;
-    }
-
-    /**
-     * 付款码支付
-     * 官方文档地址: https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1
-     */
-    public function micropay($orderNo, $total_fee, $ip, $shopName, $auth_code)
-    {
-        $url = $this->apiUrl.'micropay';
-
-        $params = [
-            'appid'  => $this->appid, // 小程序ID/微信开放平台审核通过的应用APPID
-            'mch_id' => $this->mch_id, // 商户号
-            'nonce_str' => md5(md5(time().'qianniao.vip')), // 32位随机字符串
-            'body'  => $shopName.'-'.'线上商城',
-            'out_trade_no' => $orderNo, // 商户订单号
-            'total_fee'  => yuanToFen($total_fee), // 订单总金额,单位分
-            'spbill_create_ip' => $ip, // 终端ip
-            'auth_code' => $auth_code,
-        ];
-        $params['sign'] = self::getSign($params);
-        $post_xml = $this->arrayToWeiXinXml($params);
-        $curl_content = request($url, $post_xml);
-
-        if($curl_content['httpcode'] != '200'){
-            return ResultWrapper::fail($curl_content['errorMsg'], ErrorCode::$apiNotResult);
-        }
-
-        $response_content = (array)simplexml_load_string($curl_content['content'], 'SimpleXMLElement', LIBXML_NOCDATA);
-            if($response_content['return_code'] != 'SUCCESS'){
-            return ResultWrapper::fail($response_content['return_msg'], ErrorCode::$weixinPayError);
-        }
-
-        if($response_content['result_code'] != 'SUCCESS' && $response_content['err_code'] != 'USERPAYING' ){
-            return ResultWrapper::fail($response_content['err_code_des'], ErrorCode::$weixinPayError);
-        }
-
-        // 20s内查询支付状态,如果有明确错误直接返回错误,其他情况继续查询。如果成功直接返回成功
-        for($i=1; $i<=10; $i++)
-        {
-            $url = $this->apiUrl.'orderquery';
-            $params = [
-                'appid'  => $this->appid, // 小程序ID/微信开放平台审核通过的应用APPID
-                'mch_id' => $this->mch_id, // 商户号
-                'nonce_str' => md5(md5(time().'qianniao.vip')), // 32位随机字符串
-                'out_trade_no' => $orderNo, // 商户订单号
-            ];
-
-            $params['sign'] = self::getSign($params);
-            $post_xml = $this->arrayToWeiXinXml($params);
-            $curl_content = request($url, $post_xml);
-
-            if($curl_content['httpcode'] != '200'){
-                return ResultWrapper::fail($curl_content['errorMsg'], ErrorCode::$apiNotResult);
-            }
-
-            $response_content = (array)simplexml_load_string($curl_content['content'], 'SimpleXMLElement', LIBXML_NOCDATA);
-            if($response_content['return_code'] != 'SUCCESS'){
-                return ResultWrapper::fail($response_content['return_msg'], ErrorCode::$weixinPayError);
-            }
-
-            if($response_content['result_code'] != 'SUCCESS' && $response_content['err_code'] == 'ORDERNOTEXIST'){
-                return ResultWrapper::fail($response_content['err_code_des'], ErrorCode::$weixinPayError);
-            }
-
-            if($response_content['return_code'] == 'SUCCESS' &&  $response_content['result_code'] == 'SUCCESS' && $response_content['trade_state'] == 'SUCCESS'){
-                return ResultWrapper::success($response_content['trade_state']);
-            }
-
-            sleep(2);
-        }
-
-        // 20s内没有支付则撤销订单
-        for($i=1; $i<=10; $i++){
-            $url = $this->baseUrl.'secapi/pay/reverse';
-            $params = [
-                'appid'  => $this->appid, // 小程序ID/微信开放平台审核通过的应用APPID
-                'mch_id' => $this->mch_id, // 商户号
-                'nonce_str' => md5(md5(time().'qianniao.vip')), // 32位随机字符串
-                'out_trade_no' => $orderNo, // 商户订单号
-            ];
-
-            $params['sign'] = self::getSign($params);
-            $post_xml = $this->arrayToWeiXinXml($params);
-            $curl_content = request($url, $post_xml, 10, false, [], true);
-
-            if($curl_content['httpcode'] != '200'){
-                return ResultWrapper::fail($curl_content['errorMsg'], ErrorCode::$apiNotResult);
-            }
-            $response_content = (array)simplexml_load_string($curl_content['content'], 'SimpleXMLElement', LIBXML_NOCDATA);
-            if($response_content['return_code'] != 'SUCCESS'){
-                return ResultWrapper::fail($response_content['return_msg'], ErrorCode::$weixinPayError);
-            }
-
-            if($response_content['result_code'] != 'SUCCESS' && $response_content['recall'] == 'N'){
-                return ResultWrapper::fail($response_content['err_code_des'], ErrorCode::$weixinPayError);
-            }
-
-            if($response_content['return_code'] == 'SUCCESS' &&  $response_content['result_code'] == 'SUCCESS' && $response_content['recall'] == 'N'){
-                return ResultWrapper::success($response_content['result_code']);
-            }
-        }
-
-    }
-
-
-    /**
-     * H5查询支付状态接口
-     */
-    public function orderquery($orderNo)
-    {
-        $url = $this->apiUrl.'orderquery';
-        $params = [
-            'appid'  => $this->appid, // 小程序ID/微信开放平台审核通过的应用APPID
-            'mch_id' => $this->mch_id, // 商户号
-            'nonce_str' => md5(md5(time().'qianniao.vip')), // 32位随机字符串
-            'out_trade_no' => $orderNo, // 商户订单号
-        ];
-
-        $params['sign'] = self::getSign($params);
-        $post_xml = $this->arrayToWeiXinXml($params);
-        $curl_content = request($url, $post_xml);
-
-        $result = $this->commonResult($curl_content);
-        if(!$result->isSuccess()){
-            return ResultWrapper::fail($result->getData(), $result->getErrorCode());
-        }
-        $response_content = $result->getData();
-
-        $trade_state = $response_content['trade_state'];
-
-        return ResultWrapper::success($trade_state);
-    }
-
-    /**
-     * 申请退款API
-     * 官方文档地址:https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_4
-     */
-    public function transfers($outerTradeNo, $out_refund_no, $refundMoney, $orderMoney, $sslData)
-    {
-        $url = $this->baseUrl.'secapi/pay/refund';
-        $params = [
-            'appid'  => $this->appid,
-            'mch_id' => $this->mch_id,
-            'nonce_str' => md5(md5(time().'qianniao.vip')), // 32位随机字符串
-            'transaction_id' => $outerTradeNo, // 微信交易号
-            'out_refund_no'  => $out_refund_no, // 商户退款单号
-            'refund_fee' => yuanToFen($refundMoney), // 退款金额
-            'total_fee'  => yuanToFen($orderMoney),  // 订单总金额
-        ];
-
-        $params['sign'] = self::getSign($params);
-        $post_xml = $this->arrayToWeiXinXml($params);
-        $curl_content = request($url, $post_xml, 10, false, [], true, $sslData);
-
-        $result = $this->commonResult($curl_content);
-        if(!$result->isSuccess()){
-            return ResultWrapper::fail($result->getData(), $result->getErrorCode());
-        }
-        $response_content = $result->getData();
-
-        return ResultWrapper::success($response_content['refund_id']);
-    }
-
-    /**
-     * 公共处理返回结果方法
-     */
-    public function commonResult($curl_content)
-    {
-        if($curl_content['httpcode'] == '200'){
-            $response_content = (array)simplexml_load_string($curl_content['content'], 'SimpleXMLElement', LIBXML_NOCDATA);
-            if($response_content['return_code'] == 'SUCCESS'){
-                if($response_content['result_code'] == 'SUCCESS'){
-                    return ResultWrapper::success($response_content);
-                }else{
-                    return ResultWrapper::fail($response_content['err_code_des'], ErrorCode::$weixinPayError);
-                }
-            }else{
-                return ResultWrapper::fail($response_content['return_msg'], ErrorCode::$weixinPayError);
-            }
-        }else{
-            return ResultWrapper::fail($curl_content['errorMsg'], ErrorCode::$apiNotResult);
-        }
-    }
-
-    /**
-     * 生成签名方法
-     * 官方接口地址: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=4_3
-     * 官方签名测试地址: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=20_1
-     * @param $parm
-     * @return string
-     */
-    public function getSign($parm)
-    {
-        //非空参数值的参数按照参数名ASCII码从小到大排序(字典序)
-        if(ksort($parm)){
-            $stringA = '';
-            //使用URL键值对的格式拼接成字符串stringA
-            foreach($parm as $key => $value){
-                if($value == 0 || !empty($value)){
-                    $stringA .=$key.'='.$value.'&';
-                }
-            }
-        }else{
-            echo "对参数排序出错";
-            exit();
-        }
-
-        //在stringA最后拼接上key=商户支付密钥
-        $stringSignTemp = $stringA.'key='.$this->config["ApiV2Key"];
-
-        //对stringSignTemp进行MD5运算,再将得到的字符串所有字符转换为大写
-        $signValue = strtoupper(md5($stringSignTemp));
-        return $signValue;
-    }
-    
-    
-    
-    
-    //数组转xml
-    public function arrayToWeiXinXml($arr)
-    {
-        $xml = '<xml>';
-        foreach($arr as $key => $value){
-            if (is_string($value)) {
-                $xml .= '<' . $key . '><![CDATA[' . $value . ']]></' . $key . '>';
-            } else {
-                $xml .= '<' . $key . '>' . $value . '</' . $key . '>';
-            }
-        }
-        $xml .='</xml>';
-        return $xml;
-    }
-
-}

+ 0 - 204
library/utils/weixinPayV2Old.php

@@ -1,204 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | [ WE CAN DO IT MORE SIMPLE  ]
-// +----------------------------------------------------------------------
-// | Copyright (c) 2018-2020 rights reserved.
-// +----------------------------------------------------------------------
-// | Author: YingZi
-// +----------------------------------------------------------------------
-// | Date: 2022-05-27 15:14
-// +----------------------------------------------------------------------
-declare (strict_types = 1);
-namespace library\utils;
-use WeChatPay\Builder;
-use WeChatPay\Formatter;
-use WeChatPay\Transformer;
-use WeChatPay\Crypto\Hash;
-use WeChatPay\Crypto\AesEcb;
-use WeChatPay\Crypto\Rsa;
-use WeChatPay\Crypto\AesGcm;
-
-use WeChatPay\Util\PemUtil;
-use WeChatPay\Request\WeChatPayTradeOutTradeNoQueryRequest;
-
-class weixinPayV2{
-    private $config;
-    private $client;
-    public  $errorMsg="系统错误";
-    private $merchantPrivateKeyInstance="";
-    /**
-     * 构造函数
-     * @param type $config
-     */
-    public function __construct($config = [])
-    {
-        if(empty($config)) $config = config('wxpay');
-        $this->config = $config;
-        $instance = Builder::factory([
-            'mchid'      => $this->config["MCHID"],
-            'serial'     => 'nop',//商户证书序列号,不使用APIv3可填任意值
-            'privateKey' => 'any',//商户API私钥,不使用APIv3可填任意值
-            'certs'      => ['any' => null],//不使用APIv3可填任意值
-            'secret'     => $this->config["ApiV2Key"],
-            'merchant' => [
-                'cert' => $this->config["ApiclientCert"],
-                'key'  => $this->config["ApiclientKey"],
-            ],
-        ]);
-        $this->client = $instance;
-    }
-    /**
-     * 微信小程序支付
-     * @param type $post
-     */
-    public function wxmpPay($post=[]){
-        $apiUrl = "pay/unifiedorder";
-        $jsonData = [];
-        //商户信息
-        $jsonData["appid"] = $this->config["APPID"];
-        $jsonData["mchid"] = $this->config["MCHID"];
-        $jsonData["notify_url"] = $this->config["NOTIFY_URL"];
-        //必填参数
-        $jsonData["description"]  = $post["description"];//描述
-        $jsonData["out_trade_no"] = $post["out_trade_no"];//商户订单号
-        $jsonData["amount"] = [
-            "total"=> (int)(floatval($post["total"])*100),//订单金额,分
-            "currency" => 'CNY'
-        ];
-        $jsonData["scene_info"] = [//支付场景描述
-            "payer_client_ip"=>empty($post["payer_client_ip"])?"127.0.0.1":$post["payer_client_ip"],//客户端IP
-        ];
-        $jsonData["time_expire"] = date("Y-m-d\TH:i:s+08:00",time()+30*60);//交易结束时间2018-06-08T10:34:56+08:00
-        $jsonData["payer"]=[
-            "openid"=>$post["openid"]
-        ];
-        $result = $this->clientHttp("POST", $apiUrl, $jsonData);
-        if(empty($result)){
-            if(empty($this->errorMsg)){
-                $this->errorMsg = "支付错误001";
-            }
-            return false;
-        }
-        $resuleAr = json_decode($result,true);
-        if(empty($resuleAr)){
-            if(empty($this->errorMsg)){
-                $this->errorMsg = "支付错误002";
-            }
-            return false;
-        }
-        if(empty($resuleAr["prepay_id"])){
-            if(empty($this->errorMsg)){
-                $this->errorMsg = "支付错误003";
-            }
-            return false;
-        }
-        //组装支付参数
-        $payInfo=array();
-        $data=$this->makeSign(["appId"=>$this->config["APPID"],"prepay_id"=>$resuleAr["prepay_id"]]);
-        $data["payData"] = $jsonData;
-        return $data;
-    }
-    /**
-     * 查询订单
-     * @param type $out_trade_no 商户订单号
-     */
-    public function searchOrder($out_trade_no){
-        $apiUrl = "v3/pay/transactions/out-trade-no/{out_trade_no}";
-        $result = $this->clientHttp("GET", $apiUrl,[
-            "out_trade_no"=>$out_trade_no,
-            "query"=>["mchid"=>$this->config["MCHID"]],
-        ]);
-        return $result;
-    }
-    /**
-     * 关闭订单
-     * @param type $out_trade_no 商户订单号
-     */
-    public function closeOrder($out_trade_no){
-        $apiUrl = "v3/pay/transactions/out-trade-no/{out_trade_no}/close";
-        $result = $this->clientHttp("GET", $apiUrl,[
-            "out_trade_no"=>$out_trade_no,
-            "query"=>["mchid"=>$this->config["MCHID"]],
-        ]);
-        return $result;
-    }
-    /**
-     * 生成签名
-     * @param type $info
-     * @return string
-     */
-    private function makeSign($info){
-        $params = [
-            'appId'     => $info["appId"],
-            'timeStamp' => (string)Formatter::timestamp(),
-            'nonceStr'  => Formatter::nonce(),
-            'package'   => 'prepay_id='.$info["prepay_id"],
-        ];
-        $params["paySign"] = Rsa::sign(Formatter::joinedByLineFeed(...array_values($params)),$this->merchantPrivateKeyInstance);
-        $params["signType"] = 'RSA';
-        return $params;
-    }
-    /**
-     * 解密回调参数
-     * @param type $data
-     * @return type
-     */
-    public function aesGcmDecrypt($data){
-        // 加密文本消息解密
-        $inBodyResource = AesGcm::decrypt($data["ciphertext"], $this->config["apiv3Key"], $data["nonce"], $data["associated_data"]);
-        // 把解密后的文本转换为PHP Array数组
-        $inBodyResourceArray = (array)json_decode($inBodyResource, true);
-        return $inBodyResourceArray;
-    }
-    /**
-     * http提交[同步请求]
-     * @param type $type
-     * @param type $url 示例:v3/pay/transactions/native
-     * @param type $json
-     * @return boolean
-     */
-    private function clientHttp($type='POST',$url='',$json=[]){
-        try {
-            $resp=null;
-            if($type=="POST"){
-                $resp = $this->client->chain($url)->post(['json' => $json]);
-                if(empty($json)){
-                    $resp = $this->client->chain($url)->post();
-                }else{
-                    $resp = $this->client->chain($url)->post(['json' => $json]);
-                }
-            }
-            if($type=="GET"){
-                if(empty($json)){
-                    $resp = $this->client->chain($url)->get();
-                }else{
-                    $resp = $this->client->chain($url)->get($json);
-                }
-            }
-            if(empty($resp)){
-                $this->errorMsg="提交方式错误";
-                return false;
-            }
-            $statusCode =  $resp->getStatusCode();
-            if ($statusCode == 200) { //处理成功
-                return $resp->getBody()->getContents();
-            } else if ($statusCode == 204) { //处理成功,无返回Body
-                $this->errorMsg = "处理成功,无返回Body";
-                return false;
-            }else{
-                $this->errorMsg = "未知错误";
-                return false;
-            }
-        } catch (\Exception $e) {
-            // 进行错误处理
-            $this->errorMsg =  $e->getMessage();
-            if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
-                $r = $e->getResponse();
-                $this->errorMsg=$r->getStatusCode()."".$r->getReasonPhrase().$r->getBody();
-            }
-            return false;
-        }
-    }
-    
-}
-

+ 0 - 337
library/utils/wxpay.php

@@ -1,337 +0,0 @@
-<?php
-
-declare (strict_types = 1);
-namespace library\utils;
-// +----------------------------------------------------------------------
-// | [ WE CAN DO IT MORE SIMPLE  ]
-// +----------------------------------------------------------------------
-// | Copyright (c) 2018-2020 rights reserved.
-// +----------------------------------------------------------------------
-// | Author: TABLE ME
-// +----------------------------------------------------------------------
-// | Date: 2020-10-04 18:31
-// +----------------------------------------------------------------------
-
-use GuzzleHttp\Exception\RequestException;
-use WechatPay\GuzzleMiddleware\WechatPayMiddleware;
-use WechatPay\GuzzleMiddleware\Util\PemUtil;
-use GuzzleHttp\HandlerStack as HandlerStackWx;
-use GuzzleHttp\Client as GuzzleHttpClient;
-
-class wxpay {
-    
-    const KEY_LENGTH_BYTE = 32;
-    const AUTH_TAG_LENGTH_BYTE = 16;
-    
-    private $config;
-    private $client;
-    public  $errorMsg = "操作失败";
-    
-    
-    
-    /**
-     * 构造函数
-     * @param type $config
-     */
-    public function __construct($config = [])
-    {
-        if(empty($config)) $config = config('wxpay');
-        $this->config = $config;
-        $merchantPrivateKey = PemUtil::loadPrivateKey($this->config["PrivateKey"]); // 商户私钥文件路径
-        // 微信支付平台配置
-        $wechatpayCertificate = PemUtil::loadCertificate($this->config["Certificate"]); // 微信支付平台证书文件路径
-        // 构造一个WechatPayMiddleware
-        $wechatpayMiddleware = WechatPayMiddleware::builder()
-            ->withMerchant($this->config["MCHID"],$this->config["merchantSerialNumber"], $merchantPrivateKey) // 传入商户相关配置
-            ->withWechatPay([ $wechatpayCertificate ]) // 可传入多个微信支付平台证书,参数类型为array
-            ->build();
-        // 将WechatPayMiddleware添加到Guzzle的HandlerStack中
-        $stack = HandlerStackWx::create();
-        $stack->push($wechatpayMiddleware, 'wechatpay');
-        // 创建Guzzle HTTP Client时,将HandlerStack传入,接下来,正常使用Guzzle发起API请求,WechatPayMiddleware会自动地处理签名和验签
-        $this->client = new GuzzleHttpClient(['handler' => $stack]);
-    }
-    /**
-     * 微信小程序支付
-     * @param type $post
-     */
-    public function wxmpPay($post=[]){
-        $apiUrl = "https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi";
-        $jsonData = [];
-        //商户信息
-        $jsonData["appid"] = $this->config["APPID"];
-        $jsonData["mchid"] = $this->config["MCHID"];
-        $jsonData["notify_url"] = $this->config["NOTIFY_URL"];
-        //必填参数
-        $jsonData["description"] = $post["description"];//描述
-        $jsonData["out_trade_no"] = $post["out_trade_no"];//商户订单号
-        $jsonData["amount"] = [
-            "total"=> floatval($post["total"])*100,//订单金额,分
-        ];
-//        $jsonData["scene_info"] = [//支付场景描述
-//            "payer_client_ip"=>$post["payer_client_ip"],//客户端IP
-//        ];
-        $jsonData["time_expire"] = date("Y-m-d\TH:i:s+08:00",time()+30*60);//交易结束时间2018-06-08T10:34:56+08:00
-        $jsonData["payer"]=[
-            "openid"=>$post["openid"]
-        ];
-        $result = $this->clientHttp("POST", $apiUrl, $jsonData);
-        if(empty($result)){
-            $this->errorMsg = "支付错误001";
-            return false;
-        }
-        $resuleAr = json_decode($result,true);
-        if(empty($resuleAr)){
-            $this->errorMsg = "支付错误002";
-            return false;
-        }
-        if(empty($resuleAr["prepay_id"])){
-            $this->errorMsg = "支付错误003";
-            return false;
-        }
-        //组装支付参数
-        $payInfo=array();
-        $info['appId'] = $this->config["APPID"];
-        $info['timeStamp'] = time();
-        $info['nonceStr'] = $this->random_number(); //生成随机数,下面有生成实例,统一下单接口需要
-        $info["package"] = "prepay_id=".$result['prepay_id'];
-        $info['signType'] = 'MD5';
-        $info['paySign'] = $this->MakeSign($info);
-        return $info;
-    }
-    /**
-     * h5支付
-     */
-    public function wapPay($post=[]){
-        $apiUrl = "https://api.mch.weixin.qq.com/v3/pay/transactions/h5";
-        $jsonData = [];
-        //商户信息
-        $jsonData["appid"] = $this->config["APPID"];
-        $jsonData["mchid"] = $this->config["MCHID"];
-        $jsonData["notify_url"] = $this->config["NOTIFY_URL"];
-        //必填参数
-        $jsonData["description"] = $post["description"];//描述
-        $jsonData["out_trade_no"] = $post["out_trade_no"];//商户订单号
-        $jsonData["amount"] = [
-            "total"=> floatval($post["total"])*100,//订单金额,分
-        ];
-        $jsonData["scene_info"] = [//支付场景描述
-            "payer_client_ip"=>$post["payer_client_ip"],//客户端IP
-            "h5_info"=>[//h5场景信息
-                "type"=>"Wap",//iOS, Android, Wap
-            ]
-        ];
-        $jsonData["time_expire"] = date("Y-m-d\TH:i:s+08:00",time()+30*60);//交易结束时间2018-06-08T10:34:56+08:00
-        $result = $this->clientHttp("POST", $apiUrl, $jsonData);
-        if($result){
-            $resuleAr = json_decode($result,true);
-            if(empty($resuleAr) || empty($resuleAr["h5_url"])){
-                $this->errorMsg = "h5_url不存在";
-                return false;
-            }
-            return $resuleAr["h5_url"];
-        }
-        return false;
-    }
-    
-    
-    /**
-     * app支付
-     */
-    public function appPay($post=[]){
-        $apiUrl = "https://api.mch.weixin.qq.com/v3/pay/transactions/app";
-        $jsonData = [];
-        //商户信息
-        $jsonData["appid"] = $this->config["APPID"];
-        $jsonData["mchid"] = $this->config["MCHID"];
-        $jsonData["notify_url"] = $this->config["NOTIFY_URL"];
-        //必填参数
-        $jsonData["description"] = $post["description"];//描述
-        $jsonData["out_trade_no"] = $post["out_trade_no"];//商户订单号
-        $jsonData["amount"] = [
-            "total"=> floatval($post["total"])*100,//订单金额,分
-        ];
-        $jsonData["scene_info"] = [//支付场景描述
-            "payer_client_ip"=>$post["payer_client_ip"],//客户端IP
-        ];
-        $jsonData["time_expire"] = date("Y-m-d\TH:i:s+08:00",time()+30*60);//交易结束时间2018-06-08T10:34:56+08:00
-        $this->clientHttp("POST", $apiUrl, $jsonData);
-    }
-    
-    
-    
-    
-    /**
-     * 商户订单号
-     * @param type $out_trade_no
-     */
-    public function searchNotifyOrder($out_trade_no){
-        $apiUrl = "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{$out_trade_no}?mchid={$this->config["MCHID"]}";
-        return $this->clientHttp("GET", $apiUrl);
-    }
-    /**
-     * 关闭支付订单
-     * @param type $out_trade_no
-     */
-    public function closePayOrder($out_trade_no){
-        $apiUrl = "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{$out_trade_no}/close";
-        $postData=array(
-            "out_trade_no"=>$out_trade_no,
-            "mchid"=>$this->config["MCHID"],
-        );
-        return $this->clientHttp("POST", $apiUrl,$postData);
-    }
-    
-    /**
-     * Decrypt AEAD_AES_256_GCM ciphertext
-     *
-     * @param string    $associatedData     AES GCM additional authentication data
-     * @param string    $nonceStr           AES GCM nonce
-     * @param string    $ciphertext         AES GCM cipher text
-     *
-     * @return string|bool      Decrypted string on success or FALSE on failure
-     */
-    public function decryptToString($associatedData, $nonceStr, $ciphertext)
-    {
-        if (strlen($this->config['aesKey']) != self::KEY_LENGTH_BYTE) {
-            $this->errorMsg = "无效的ApiV3Key,长度应为32个字节";
-            return false;
-        }
-        
-        $ciphertext = \base64_decode($ciphertext);
-        if (strlen($ciphertext) <= self::AUTH_TAG_LENGTH_BYTE) {
-            $this->errorMsg = "字符长度错误";
-            return false;
-        }
-        // ext-sodium (default installed on >= PHP 7.2)
-        if (function_exists('\sodium_crypto_aead_aes256gcm_is_available') && \sodium_crypto_aead_aes256gcm_is_available()) {
-            return \sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $this->config['aesKey']);
-        }
-        // ext-libsodium (need install libsodium-php 1.x via pecl)
-        if (function_exists('\Sodium\crypto_aead_aes256gcm_is_available') && \Sodium\crypto_aead_aes256gcm_is_available()) {
-            return \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $this->config['aesKey']);
-        }
-        // openssl (PHP >= 7.1 support AEAD)
-        if (PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', \openssl_get_cipher_methods())) {
-            $ctext = substr($ciphertext, 0, -self::AUTH_TAG_LENGTH_BYTE);
-            $authTag = substr($ciphertext, -self::AUTH_TAG_LENGTH_BYTE);
-            return \openssl_decrypt($ctext, 'aes-256-gcm', $this->config['aesKey'], \OPENSSL_RAW_DATA, $nonceStr,$authTag, $associatedData);
-        }
-        $this->errorMsg = "AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php";
-        return false;
-//        throw new \RuntimeException('AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php');
-    }
-    
-    /**
-     * http提交
-     */
-    public function clientHttp($type='POST',$url='',$json=[]){
-        $httpData = [];
-        if($type == 'POST'){
-            $httpData["json"] = $json;
-        }
-        $httpData["headers"] = ['Accept' => 'application/json'];
-        $resp = $this->client->request($type,$url,$httpData);
-        $statusCode = $resp->getStatusCode();
-        if ($statusCode == 200) { //处理成功
-            return $resp->getBody()->getContents();
-        } else if ($statusCode == 204) { //处理成功,无返回Body
-            $this->errorMsg = "处理成功,无返回Body";
-            return false;
-        }else{
-            $this->errorMsg = "未知错误";
-            return false;
-        }
-//        try{
-//            $resp = $this->client->request($type,$url,$httpData);
-//            $statusCode = $resp->getStatusCode();
-//            var_dump($statusCode);
-//            if ($statusCode == 200) { //处理成功
-//                return $resp->getBody()->getContents();
-//            } else if ($statusCode == 204) { //处理成功,无返回Body
-//                $this->errorMsg = "处理成功,无返回Body";
-//                return false;
-//            }else{
-//                $this->errorMsg = "未知错误";
-//                return false;
-//            }
-//        } catch (RequestException $e){
-//            var_dump($e);
-//            // 进行错误处理
-//            $this->errorMsg = $e->getMessage();
-//            if ($e->hasResponse()) {
-//                $this->errorMsg = $e->getResponse()->getBody()->getContents();
-////                $this->errorMsg = "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody();
-//            }
-//            return false;
-//        }
-    }
-
-    /**
-     * 生成签名
-     * @return 签名,本函数不覆盖sign成员变量,如要设置签名需要调用SetSign方法赋值
-     */
-    public function MakeSign($values) {
-        //签名步骤一:按字典序排序参数
-        ksort($values);
-        $string = $this->ToUrlParams($values);
-        //签名步骤二:在string后加入KEY
-        $string = $string . "&key=" . \WxPayConfig::KEY;
-        //签名步骤三:MD5加密
-        $string = md5($string);
-        //签名步骤四:所有字符转为大写
-        $result = strtoupper($string);
-        return $result;
-    }
-    /**
-     * 参数数组转换为url参数
-     * @param array $urlObj
-     */
-    private function ToUrlParams($urlObj) {
-        $buff = "";
-        foreach ($urlObj as $k => $v) {
-            $buff .= $k . "=" . $v . "&";
-        }
-        $buff = trim($buff, "&");
-        return $buff;
-    }
-    /**
-     * 生成随机字符串
-     * @param type $len
-     * @param type $format
-     * @return type
-     */
-    public function random_number($len = 21, $format = 'ALL') {
-        $is_abc = $is_numer = 0;
-        $password = $tmp = '';
-        switch ($format) {
-            case 'ALL':
-                $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
-                break;
-            case 'CHAR':
-                $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
-                break;
-            case 'NUMBER':
-                $chars = '0123456789';
-                break;
-            default :
-                $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
-                break;
-        } 
-        mt_srand((double) microtime() * 1000000 * getmypid());
-        while (strlen($password) < $len) {
-            $tmp = substr($chars, (mt_rand() % strlen($chars)), 1);
-            if (($is_numer <> 1 && is_numeric($tmp) && $tmp > 0 ) || $format == 'CHAR') {
-                $is_numer = 1;
-            }
-            if (($is_abc <> 1 && preg_match('/[a-zA-Z]/', $tmp)) || $format == 'NUMBER') {
-                $is_abc = 1;
-            }
-            $password .= $tmp;
-        }
-        if ($is_numer <> 1 || $is_abc <> 1 || empty($password)) {
-            $password = $this->random_number($len, $format);
-        }
-        return $password;
-    }
-}