关于tp5使用微信支付宝app支付、扫码支付

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_29202427/article/details/82629820
  • 业务需求
    客户需要在app上、web网站上接入微信支付支付
    2.准备
    前期准备商家在微信、蚂蚁金服申请支付,具体流程参考支付文档申请流程
    3.配置
    前期我将一些配置配置在与database.php文件目录的config.php文件下,具体代码如下:

  • 配置

<?php
return [
    // +----------------------------------------------------------------------
    // | 应用设置
    // +----------------------------------------------------------------------

    // 应用命名空间
    'app_namespace'          => 'app',
    // 应用调试模式
    'app_debug'              => false,
    // 应用Trace
    'app_trace'              => false,
    // 应用模式状态
    'app_status'             => '',
    // 是否支持多模块
    'app_multi_module'       => true,
    // 入口自动绑定模块
    'auto_bind_module'       => false,
    // 注册的根命名空间
    'root_namespace'         => [],
    // 扩展配置文件
    'extra_config_list'      => ['database', 'validate'],
    // 扩展函数文件
    'extra_file_list'        => [THINK_PATH . 'helper' . EXT],
    // 默认输出类型
    'default_return_type'    => 'html',
    // 默认AJAX 数据返回格式,可选json xml ...
    'default_ajax_return'    => 'json',
    // 默认JSONP格式返回的处理方法
    'default_jsonp_handler'  => 'jsonpReturn',
    // 默认JSONP处理方法
    'var_jsonp_handler'      => 'callback',
    // 默认时区
    'default_timezone'       => 'PRC',
    // 是否开启多语言
    'lang_switch_on'         => false,
    // 默认全局过滤方法 用逗号分隔多个
    'default_filter'         => '',
    // 默认语言
    'default_lang'           => 'zh-cn',
    // 应用类库后缀
    'class_suffix'           => false,
    // 控制器类后缀
    'controller_suffix'      => false,

    // +----------------------------------------------------------------------
    // | 模块设置
    // +----------------------------------------------------------------------

    // 默认模块名
    'default_module'         => 'index',
    // 禁止访问模块
    'deny_module_list'       => ['common'],
    // 默认控制器名
    'default_controller'     => 'Index',
    // 默认操作名
    'default_action'         => 'index',
    // 默认验证器
    'default_validate'       => '',
    // 默认的空控制器名
    'empty_controller'       => 'Error',
    // 操作方法后缀
    'action_suffix'          => '',
    // 自动搜索控制器
    'controller_auto_search' => false,

    // +----------------------------------------------------------------------
    // | URL设置
    // +----------------------------------------------------------------------

    // PATHINFO变量名 用于兼容模式
    'var_pathinfo'           => 's',
    // 兼容PATH_INFO获取
    'pathinfo_fetch'         => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'],
    // pathinfo分隔符
    'pathinfo_depr'          => '/',
    // URL伪静态后缀
    'url_html_suffix'        => 'html',
    // URL普通方式参数 用于自动生成
    'url_common_param'       => false,
    // URL参数方式 0 按名称成对解析 1 按顺序解析
    'url_param_type'         => 0,
    // 是否开启路由
    'url_route_on'           => true,
    // 路由配置文件(支持配置多个)
    'route_config_file'      => ['route'],
    // 是否强制使用路由
    'url_route_must'         => false,
    // 域名部署
    'url_domain_deploy'      => false,
    // 域名根,如thinkphp.cn
    'url_domain_root'        => '',
    // 是否自动转换URL中的控制器和操作名
    'url_convert'            => true,
    // 默认的访问控制器层
    'url_controller_layer'   => 'controller',
    // 表单请求类型伪装变量
    'var_method'             => '_method',

    // +----------------------------------------------------------------------
    // | 模板设置
    // +----------------------------------------------------------------------


    // 视图输出字符串内容替换
    'view_replace_str'       => [],
    // 默认跳转页面对应的模板文件
    'dispatch_success_tmpl'  => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
    'dispatch_error_tmpl'    => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',

    // +----------------------------------------------------------------------
    // | 异常及错误设置
    // +----------------------------------------------------------------------

    // 异常页面的模板文件
    'exception_tmpl'         => THINK_PATH . 'tpl' . DS . 'think_exception.tpl',

    // 错误显示信息,非调试模式有效
    'error_message'          => '页面错误!请稍后再试~',
    // 显示错误信息
    'show_error_msg'         => false,
    // 异常处理handle类 留空使用 \think\exception\Handle
    'exception_handle'       => '',

    // +----------------------------------------------------------------------
    // | 日志设置
    // +----------------------------------------------------------------------

    'log'                    => [
        // 日志记录方式,内置 file socket 支持扩展
        'type'  => 'File',
        // 日志保存目录
        'path'  => LOG_PATH,
        // 日志记录级别
        'level' => [],
    ],

    // +----------------------------------------------------------------------
    // | Trace设置 开启 app_trace 后 有效
    // +----------------------------------------------------------------------
    'trace'                  => [
        // 内置Html Console 支持扩展
        'type' => 'Html',
    ],


    // +----------------------------------------------------------------------
    // | 缓存设置
    // +----------------------------------------------------------------------

    'cache'                  => [
        // 驱动方式
        'type'   => 'File',
        // 缓存保存目录
        'path'   => CACHE_PATH,
        // 缓存前缀
        'prefix' => '',
        // 缓存有效期 0表示永久缓存
        'expire' => 0,
    ],

    // +----------------------------------------------------------------------
    // | 会话设置
    // +----------------------------------------------------------------------

    'session'                => [
        'id'             => '',
        // SESSION_ID的提交变量,解决flash上传跨域
        'var_session_id' => '',
        // SESSION 前缀
        'prefix'         => 'dspx',
        // 驱动方式 支持redis memcache memcached
        'type'           => '',
        // 是否自动开启 SESSION
        'auto_start'     => true,
    ],

    // +----------------------------------------------------------------------
    // | Cookie设置
    // +----------------------------------------------------------------------
    'cookie'                 => [
        // cookie 名称前缀
        'prefix'    => '',
        // cookie 保存时间
        'expire'    => 0,
        // cookie 保存路径
        'path'      => '/',
        // cookie 有效域名
        'domain'    => '',
        //  cookie 启用安全传输
        'secure'    => false,
        // httponly设置
        'httponly'  => '',
        // 是否使用 setcookie
        'setcookie' => true,
    ],

    'AUTH_CODE' => 'zheng_an',

    //分页配置
    'paginate'               => [
        'type'      => 'bootstrap',
        'var_page'  => 'page',
        'list_rows' => 15,
    ],
    //设置项目域名
    'domain'=> 'http://www.test.com',
    'speed_domain' =>'http://play.test.com',

    //微信开发平台支付相关配置设置
    // 'OPEN_APPID'=>'jiade',//微信开放平台的应用appid
    // 'OPEN_MCHID'=>'jiade',////商户号(注册商户平台时,发置注册邮箱的商户id)
    // 'OPEN_KEY'=>'jiade',//商户平台api支付处设置的key

    'OPEN_APPID'=>'jiade',
    'OPEN_MCHID'=>'jiade',
    'OPEN_KEY'=>'jiade',
    // jiade

    //微信公众平台支付相关配置设置
    "KEY" => 'jiade',//商户API 密钥
    "APPID" => 'jiade',//公众号appID
    "SECRET" => 'jiade',//公众号AppSecret
    "MCHID" => 'jiade', //商户号id

    //支付宝相关配置
    'PRIVATEKEY' => '/g0Xro4NZLNpZxJBVaCeL7sGkCgYEA0pgBNt+7OOCLAVVRApHeJXiZXDeWjIoAu/RcBCYvldgYhdVJHTil3c7/73HVk9gLYkW9DFelJk5xYNwO4tYLRhwPiPK0dQUFaHgqJhwjLF6AnbFHy4FmbW3FaQahBezKfsAgkvXJDSc970HkjBMN3ajejUy8MCL6wR+xsB16adcCgYB5o6PnTWRYirWiFrKMOzNBaGTU9K3/sxji2sa7w+CSdx8X89beHH46K8IgBIvY/Y+H2r8tI0eO0XLrcetq+jtfSto4O/0P+5Z5ca4vP8YYr6ZVU8xj6aNE0t3U923o5RVCeinBNR6Yv6DVru7Dww62Yp+tGBYOK9hBJvjIItRdYQKBgDIRO3CtXliWYdXuT7U5ssPb2TIocR12jdghr2K5JWUNnD7tR1WwKxcB6K0ntixRF9vEUr7Fc5kY2zG4/70EQGfpsfPQKAEOMYv1zaeD1wTsbs2O4U/LsutfRqjCj7PV6QqbaOMnliYPZ1UjqE95FDnXtRmI3dDf8BfMDjWdvIW/AoGAYDBvoYQiBZej1+/cwOC2cioHhqIwz2V89wBMRi3XoTsyTKYYLDHqJBqu1BQNcyrNof1uX45zTDE0Zgsx6uksAYz/Udof/92rqJS7PEpDf2IWdzXiZJaMDDhgHi8CP2qP+K+n1s3cxnUR3OtGDQfyXCIQCiXE0CTPmgAnRPLeY5A=',//商户应用私钥
    'PUBLICKEY' => 'jiade',//支付宝公钥
    'ALIAPPID' => 'jiade',//支付宝APPID

    // //微信开发平台支付相关配置设置
    // 'OPEN_APPID'=>'jiade',//微信开放平台的应用appid
    // 'OPEN_MCHID'=>'jiade',////商户号(注册商户平台时,发置注册邮箱的商户id)
    // 'OPEN_KEY'=>'jiade',//商户平台api支付处设置的key
];
**支付宝、微信引入的东西全放如了extend文件下**
  • 下单调用逻辑
<?php
/**
 * Created by PhpStorm.
 * User: ljy
 * Date: 17/10/14
 * Time: 下午3:33
 */

namespace app\api\controller;
use Pingpp\Pingpp;
use Pingpp\Charge;
require('../extend/Pingpp/init.php');
use think\Request;
use think\Db;
use WeChatPay\WeChatPay;
use WeChatPay\Notify;
include('../extend/alipay/AopSdk.php');
class Pingxx extends Common
{
    /**
     *商城确认订单支付
     */
    public function pay_order(){
        // $data = $this->getPost();
        // $arr = $this->XmlToArr($data);
        $member = $this->checklogin();
        //记录数据到日志中
        $weChat = new WeChatPay();
        $body = "中菲购商城订单";
        $order_no=input('order_no');
        $type = input('type');

        $hotel_order = Db::name('order')->where(['order_no' => $order_no,'member_id'=>$member['member_id']])->find();
        if (!$hotel_order) error("订单错误");

        $total_fee = 1;

        switch ($type) {
            case 'wx_pub_qr':
                $Qurl = $weChat->wechat_getcode($order_no . "B" . time());
                success($Qurl);
                break;
            case 'wx':
                $weChat->wechat_apppay($body, $order_no . "B" . time(), $total_fee);
                break;
            case 'ali_app':
                $aop = new \AopClient;
                $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
                $aop->appId = config('ALIAPPID');
                $aop->rsaPrivateKey = config('PRIVATEKEY');
                $aop->format = "json";
                $aop->charset = "UTF-8";
                $aop->signType = "RSA2";
                $aop->alipayrsaPublicKey = config('PUBLICKEY');

                //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
                $request = new \AlipayTradeAppPayRequest();
                //SDK已经封装掉了公共参数,这里只需要传入业务参数
                $out_trade_no = $order_no . "B" . time();
                $bizcontent = "{\"body\":\"".$body."\"," 
                                . "\"subject\": \"AliApp\","
                                . "\"out_trade_no\": \"".$out_trade_no."\","
                                . "\"timeout_express\": \"30m\"," 
                                . "\"total_amount\": \"0.01\","
                                . "\"product_code\":\"QUICK_MSECURITY_PAY\""
                                . "}";
                $request->setNotifyUrl("http://www.zhongfeigou.com/api/pingxx/alipayCallback");
                $request->setBizContent($bizcontent);
                //这里和普通的接口调用不同,使用的是sdkExecute
                $response = $aop->sdkExecute($request);

                //htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题
                // echo htmlspecialchars($response);//就是orderString 可以直接给客户端请求,无需再做处理。
                $data = $response;
                success($data);
                break;
            case 'alipay_wap':
                require_once ('../extend/alipaywap/config.php');
                require_once ('../extend/alipaywap/pagepay/service/AlipayTradeService.php');
                require_once ('../extend/alipaywap/pagepay/buildermodel/AlipayTradePagePayContentBuilder.php');

                //商户订单号,商户网站订单系统中唯一订单号,必填
                // $out_trade_no = trim($_POST['WIDout_trade_no']);
                $out_trade_no = $order_no . "B" . time();
                //订单名称,必填
                // $subject = trim($_POST['WIDsubject']);
                $subject = 'AliWap';

                //付款金额,必填
                // $total_amount = trim($_POST['WIDtotal_amount']);
                $total_amount = '0.01';
                //商品描述,可空
                // $body = trim($_POST['WIDbody']);

                //构造参数
                $payRequestBuilder = new \AlipayTradePagePayContentBuilder();
                $payRequestBuilder->setBody($body);
                $payRequestBuilder->setSubject($subject);
                $payRequestBuilder->setTotalAmount($total_amount);
                $payRequestBuilder->setOutTradeNo($out_trade_no);

                $aop = new \AlipayTradeService($config);

                /**
                 * pagePay 电脑网站支付请求
                 * @param $builder 业务参数,使用buildmodel中的对象生成。
                 * @param $return_url 同步跳转地址,公网可以访问
                 * @param $notify_url 异步通知地址,公网可以访问
                 * @return $response 支付宝返回的信息
                */
                $response = $aop->pagePay($payRequestBuilder,$config['return_url'],$config['notify_url']);

                //输出表单
                var_dump($response);
                break;
            default:
                # code...
                break;
        }
 //---------------------------------------------
    //微信回调
        public function payCallback()
    {   
        $datas = $this->getPost();
        $result = $this->XmlToArr($datas);
        // $result = json_decode(file_get_contents('php://input'), true);
        $text = "\n\n" . date("Y-m-d H:i:s", time()) . "\n" . var_export($result, true);
        file_put_contents("callback.txt", $text, FILE_APPEND);
        if ($result['result_code'] == 'SUCCESS' && $result['return_code'] == 'SUCCESS') {
            file_put_contents("callback.txt", "111", FILE_APPEND);
            if (strpos($result['out_trade_no'], 'A') !== false) {     //确认订单支付
                file_put_contents("callback.txt", "aaa", FILE_APPEND);
                $data['pay_state'] = 2;
                $data['pay_return'] = json_encode($result);
                $data['uptime'] = date("Y-m-d H:i:s", time());
                $a = explode("A", $result["out_trade_no"]);
                $record = Db::name('Recharge')->where(['pay_number' => $a[0]])->find();
                if($record && $record['pay_state'] == '1') {
                    file_put_contents("order.txt", $a[0], FILE_APPEND);
                    $s = Db::name('Recharge')->where(['pay_number' => $a[0]])->update($data);
                    if ($s) {
                        $member = Db::name('member')->where(['member_id' => $record['member_id']])->find();
                        $money = $result['total_fee'] / 100; //支付金额
                        $diamond = $member['b_diamond'] + $record['meters'] + $record['zeng'];    //充值币相加
                        $this->insertDiamondRecord($member['member_id'], '1', '充值', $record['meters'], $record['zeng']);
                        Db::name('member')->where(['member_id' => $member['member_id']])->update(['b_diamond' => $diamond]);

                        //交易记录
                        $tradeRecord['member_id'] = $member['member_id'];
                        $tradeRecord['order_no'] = $a[0];
                        $tradeRecord['type'] = 2;
                        $tradeRecord['intime'] = date("Y-m-d H:i:s", time());
                        $tradeRecord['pay_no'] = $result["out_trade_no"];
                        $tradeRecord['amount'] = $money;
                        $tradeRecord['pay_return'] = json_encode($result);
                        Db::name('TradeRecord')->insert($tradeRecord);
                        $this->change_grade($member['member_id']);
                        success("支付成功");
                    } else {
                        error("支付失败");
                    }
                }
            } else if (strpos($result['out_trade_no'], 'B') !== false) {     //确认订单支付
                file_put_contents("callback.txt", "bbb", FILE_APPEND);
                $a = explode("B", $result["out_trade_no"]);

                $type = $result["trade_type"];
                switch ($type) {
                    case 'NATIVE':
                        $code['pay_way'] = '微信扫码';
                        break;
                    case 'APP':
                        $code['pay_way'] = '微信APP支付';
                        break;
                    case 'JSAPI':
                        $code['pay_way'] = '公众号支付';
                        break;
                    default:
                        # code...
                        break;
                }

                $order = Db::name('order')->where(['order_no' => $a[0]])->find();
                if ($order && $order['order_state'] == 'wait_pay') {
                    $data['order_state'] = 'wait_send';
                    $data['uptime'] = date("Y-m-d H:i:s", time());
                    //$data['returns'] = json_encode($result);
                    $s = Db::name('order')->where(['order_no' => $a[0]])->update($data);
                    $ss = Db::name('order')->getLastSql();
                    if ($s) {
                        $code['order_state'] = 'wait_send';
                        $code['update_time'] = date("Y-m-d H:i:s", time());
                        $code['pay_time'] = date("Y-m-d H:i:s", time());
                        $code['ping_no'] = $result["transaction_id"];   //ping++订单号
                        $code['pay_no'] = $result["out_trade_no"];
                        //$code['amount'] = $result['data']['object']['amount'] / 100;
                        $code['pay_charge'] = json_encode($result);
                        $result = Db::name('order_merchants')->where(['order_id' => $order['order_id']])->update($code);
                        $member = Db::name('member')->where(['member_id' => $order['member_id']])->find();
                        $order_goods = Db::name('order_goods')->where(['order_id' => $order['order_id']])->select();
                        foreach ($order_goods as $v) {
                            $goods = Db::name('goods')->where(['goods_id' => $v['goods_id']])->find();
                            if ($goods) {
                                $goodsInfo['total_sales'] = $goods['total_sales'] + $v['goods_num'];
                                $goodsInfo['month_sales'] = $goods['month_sales'] + $v['goods_num'];
                                $goodsInfo['day_sales'] = $goods['day_sales'] + $v['goods_num'];
                                if ($goods['goods_stock'] > $v['goods_num']) {
                                    $goodsInfo['goods_stock'] = $goods['goods_stock'] - $v['goods_num'];
                                    Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                                    if ($v['specification_id']) {
                                        $specification = Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->find();
                                        if ($specification) {
                                            if ($specification['specification_stock'] > $v['goods_num']) {
                                                $goodsSpecification['specification_stock'] = $specification['specification_stock'] - $v['goods_num'];
                                            } else {
                                                $goodsSpecification['specification_stock'] = '0';
                                            }
                                            $goodsSpecification['specification_sales'] = $specification['specification_sales'] + $v['goods_num'];
                                        }
                                        Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->update($goodsSpecification);
                                    }
                                } else {
                                    $goodsInfo['goods_stock'] = '0';
                                    Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                                }
                            }
                        }
                        //交易记录
                        $tradeRecord['member_id'] = $member['member_id'];
                        $tradeRecord['order_no'] = $a[0];
                        $tradeRecord['type'] = 1;
                        $tradeRecord['intime'] = date("Y-m-d H:i:s", time());
                        $tradeRecord['pay_no'] = $result["out_trade_no"];
                        $tradeRecord['amount'] = $result['total_fee'] / 100;
                        $tradeRecord['pay_return'] = json_encode($result);
                        Db::name('TradeRecord')->insert($tradeRecord);
                        $this->change_grade($member['member_id']);
                        success("支付成功");
                    } else {
                        error("支付失败");
                    }
                }
            } else if (strpos($result['out_trade_no'], 'C') !== false) {   //待支付订单支付
                file_put_contents("callback.txt", "ccc", FILE_APPEND);
                $a = explode("C", $result["out_trade_no"]);
                $type = $result["trade_type"];
                switch ($type) {
                    case 'NATIVE':
                        $code['pay_way'] = '微信扫码';
                        break;
                    case 'APP':
                        $code['pay_way'] = '微信APP支付';
                        break;
                    case 'JSAPI':
                        $code['pay_way'] = '公众号支付';
                        break;
                    default:
                        # code...
                        break;
                }

                $order = Db::name('order_merchants')->where(['order_no' => $a[0]])->find();
                if ($order && $order['order_state'] == 'wait_pay') {
                    $code['order_state'] = 'wait_send';
                    $code['update_time'] = date("Y-m-d H:i:s", time());
                    $code['pay_time'] = date("Y-m-d H:i:s", time());
                    $code['ping_no'] = $result["transaction_id"];   //ping++订单号
                    $code['pay_no'] = $result["out_trade_no"];
                    //$code['amount'] = $result['data']['object']['amount'] / 100;
                    $code['pay_charge'] = json_encode($result);
                    $result = Db::name('order_merchants')->where(['order_merchants_id' => $order['order_merchants_id']])->update($code);
                    $member = Db::name('member')->where(['member_id' => $order['member_id']])->find();
                    $order_goods = Db::name('order_goods')->where(['order_merchants_id' => $order['order_merchants_id']])->select();
                    foreach ($order_goods as $v) {
                        $goods = Db::name('Goods')->where(['goods_id' => $v['goods_id']])->find();
                        if ($goods) {
                            $goodsInfo['total_sales'] = $goods['total_sales'] + $v['goods_num'];
                            $goodsInfo['month_sales'] = $goods['month_sales'] + $v['goods_num'];
                            $goodsInfo['day_sales'] = $goods['day_sales'] + $v['goods_num'];
                            if ($goods['goods_stock'] > $v['goods_num']) {
                                $goodsInfo['goods_stock'] = $goods['goods_stock'] - $v['goods_num'];
                                Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                                if ($v['specification_id']) {
                                    $specification = Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->find();
                                    if ($specification) {
                                        if ($specification['specification_stock'] > $v['goods_num']) {
                                            $goodsSpecification['specification_stock'] = $specification['specification_stock'] - $v['goods_num'];
                                        } else {
                                            $goodsSpecification['specification_stock'] = '0';
                                        }
                                        $goodsSpecification['specification_sales'] = $specification['specification_sales'] + $v['goods_num'];
                                    }
                                    Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->update($goodsSpecification);
                                }
                            } else {
                                $goodsInfo['goods_stock'] = '0';
                                Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                            }
                        }
                    }

                    //交易记录
                    $tradeRecord['member_id'] = $member['member_id'];
                    $tradeRecord['order_no'] = $a[0];
                    $tradeRecord['type'] = 1;
                    $tradeRecord['intime'] = date("Y-m-d H:i:s", time());
                    $tradeRecord['pay_no'] = $result["out_trade_no"];
                    $tradeRecord['amount'] = $result['total_fee'] / 100;
                    $tradeRecord['pay_return'] = json_encode($result);
                    Db::name('TradeRecord')->insert($tradeRecord);
                    $this->change_grade($member['member_id']);
                    success("支付成功");
                }
            } else if (strpos($result['out_trade_no'], 'D') !== false) {   //待支付订单支付
                file_put_contents("callback.txt", "ddd", FILE_APPEND);
                $a = explode("D", $result["out_trade_no"]);
                $type = $result["trade_type"];
                switch ($type) {
                    case 'NATIVE':
                        $code['pay_way'] = '微信扫码';
                        break;
                    case 'APP':
                        $code['pay_way'] = '微信APP支付';
                        break;
                    case 'JSAPI':
                        $code['pay_way'] = '公众号支付';
                        break;
                    default:
                        # code...
                        break;
                }
                $order = Db::name('merchants_deposit_order')->where(['order_no' => $a[0]])->find();
                if ($order && $order['order_state'] == 'wait_pay') {
                    $code['order_state'] = 'end';
                    $code['update_time'] = date("Y-m-d H:i:s", time());
                    $code['pay_time'] = date("Y-m-d H:i:s", time());
                    //$code['amount'] = $result['data']['object']['amount'] / 100;
                    $code['pay_charge'] = json_encode($result);
                    Db::name('merchants_deposit_order')->where(['deposit_id' => $order['deposit_id']])->update($code);
                    Db::name('member')->where(['member_id' => $order['member_id']])->update(['type'=>'2']);
                    Db::name('merchants')->where(['member_id' => $order['member_id']])->update(['pay_state'=>'1']);
                    success("支付成功");
                } else {
                    error("支付失败");
                }
            }else {
                error("支付失败");
            }
        }
    }
//--------------------------------------------
支付宝回调
    public function alipayCallback()
    {   

        error_reporting(E_ALL);
        // file_put_contents("callback.txt", "\n\n", FILE_APPEND);
        // file_put_contents("callback.txt", $_POST, FILE_APPEND);
        // file_put_contents("callback.txt", "\n\n", FILE_APPEND);
        $t = "\n\n" . date("Y-m-d H:i:s", time()) . "\n" . var_export($_POST, true);
        file_put_contents("callback.txt", $t, FILE_APPEND);

        $aop = new \AopClient;
        $aop->alipayrsaPublicKey = config('PUBLICKEY');
        $flag = $aop->rsaCheckV1($_POST, NULL, "RSA2");

        if($flag == 1 && $_POST['trade_status'] == 'TRADE_SUCCESS'){
            file_put_contents("callback.txt", "111", FILE_APPEND);
            if (strpos($_POST['out_trade_no'], 'A') !== false) {     //确认订单支付
                file_put_contents("callback.txt", "aaa", FILE_APPEND);
                $data['pay_state'] = 2;
                $data['pay_return'] = json_encode($_POST);
                $data['uptime'] = date("Y-m-d H:i:s", time());
                $a = explode("A", $_POST["out_trade_no"]);
                $record = Db::name('Recharge')->where(['pay_number' => $a[0]])->find();
                if($record && $record['pay_state'] == '1') {
                    file_put_contents("order.txt", $a[0], FILE_APPEND);
                    $s = Db::name('Recharge')->where(['pay_number' => $a[0]])->update($data);
                    if ($s) {
                        $member = Db::name('member')->where(['member_id' => $record['member_id']])->find();
                        $money = $_POST['total_amount']; //支付金额
                        $diamond = $member['b_diamond'] + $record['meters'] + $record['zeng'];    //充值币相加
                        $this->insertDiamondRecord($member['member_id'], '1', '充值', $record['meters'], $record['zeng']);
                        Db::name('member')->where(['member_id' => $member['member_id']])->update(['b_diamond' => $diamond]);

                        //交易记录
                        $tradeRecord['member_id'] = $member['member_id'];
                        $tradeRecord['order_no'] = $a[0];
                        $tradeRecord['type'] = 2;
                        $tradeRecord['intime'] = date("Y-m-d H:i:s", time());
                        $tradeRecord['pay_no'] = $_POST["out_trade_no"];
                        $tradeRecord['amount'] = $money;
                        $tradeRecord['pay_return'] = json_encode($_POST);
                        Db::name('TradeRecord')->insert($tradeRecord);
                        $this->change_grade($member['member_id']);
                        echo "success"; //请不要修改或删除
                        success("支付成功");
                    } else {
                        error("支付失败");
                    }
                }
            } else if (strpos($_POST['out_trade_no'], 'B') !== false) {     //确认订单支付
                file_put_contents("callback.txt", "bbb", FILE_APPEND);
                $a = explode("B", $_POST["out_trade_no"]);

                $type = $_POST["subject"];
                switch ($type) {
                    case 'AliApp':
                        $code['pay_way'] = '支付宝APP支付';
                        break;
                    case 'AliWap':
                        $code['pay_way'] = '支付宝扫码支付';
                        break;
                    default:
                        # code...
                        break;
                }

                $order = Db::name('order')->where(['order_no' => $a[0]])->find();
                if ($order && $order['order_state'] == 'wait_pay') {
                    $data['order_state'] = 'wait_send';
                    $data['uptime'] = date("Y-m-d H:i:s", time());
                    //$data['returns'] = json_encode($result);
                    $s = Db::name('order')->where(['order_no' => $a[0]])->update($data);
                    $ss = Db::name('order')->getLastSql();

                    if ($s) {
                        $code['order_state'] = 'wait_send';
                        $code['update_time'] = date("Y-m-d H:i:s", time());
                        $code['pay_time'] = date("Y-m-d H:i:s", time());
                        $code['ping_no'] = $_POST["trade_no"];   //ping++订单号
                        $code['pay_no'] = $_POST["out_trade_no"];
                        //$code['amount'] = $result['data']['object']['amount'] / 100;
                        $code['pay_charge'] = json_encode($_POST);
                        $result = Db::name('order_merchants')->where(['order_id' => $order['order_id']])->update($code);
                        $member = Db::name('member')->where(['member_id' => $order['member_id']])->find();
                        $order_goods = Db::name('order_goods')->where(['order_id' => $order['order_id']])->select();
                        foreach ($order_goods as $v) {
                            $goods = Db::name('goods')->where(['goods_id' => $v['goods_id']])->find();
                            if ($goods) {
                                $merchant = Db::name('merchants')->where(['member_id' => $goods['member_id']])->find();
                                $goodsInfo['total_sales'] = $goods['total_sales'] + $v['goods_num'];
                                $goodsInfo['month_sales'] = $goods['month_sales'] + $v['goods_num'];
                                $goodsInfo['day_sales'] = $goods['day_sales'] + $v['goods_num'];
                                $merchantInfo['total_sales'] = $merchant['total_sales'] + $v['goods_num'];
                                $merchantInfo['month_sales'] = $merchant['month_sales'] + $v['goods_num'];
                                $merchantInfo['day_sales'] = $merchant['day_sales'] + $v['goods_num'];
                                Db::name('merchants')->where(['member_id' => $goods['member_id']])->update($merchantInfo);
                                if ($goods['goods_stock'] > $v['goods_num']) {
                                    $goodsInfo['goods_stock'] = $goods['goods_stock'] - $v['goods_num'];
                                    Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                                    if ($v['specification_id']) {
                                        $specification = Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->find();
                                        if ($specification) {
                                            if ($specification['specification_stock'] > $v['goods_num']) {
                                                $goodsSpecification['specification_stock'] = $specification['specification_stock'] - $v['goods_num'];
                                            } else {
                                                $goodsSpecification['specification_stock'] = '0';
                                            }
                                            $goodsSpecification['specification_sales'] = $specification['specification_sales'] + $v['goods_num'];
                                        }
                                        Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->update($goodsSpecification);
                                    }
                                } else {
                                    $goodsInfo['goods_stock'] = '0';
                                    Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                                }
                            }
                        }
                        //交易记录
                        $tradeRecord['member_id'] = $member['member_id'];
                        $tradeRecord['order_no'] = $a[0];
                        $tradeRecord['type'] = 1;
                        $tradeRecord['intime'] = date("Y-m-d H:i:s", time());
                        $tradeRecord['pay_no'] = $_POST["out_trade_no"];
                        $tradeRecord['amount'] = $_POST['total_amount'];
                        $tradeRecord['pay_return'] = json_encode($_POST);
                        Db::name('TradeRecord')->insert($tradeRecord);
                        $this->change_grade($member['member_id']);
                        echo "success"; //请不要修改或删除
                        success("支付成功");
                    } else {
                        error("支付失败");
                    }
                }
            } else if (strpos($_POST['out_trade_no'], 'C') !== false) {   //待支付订单支付
                $a = explode("C", $_POST["out_trade_no"]);
                $type = $_POST["subject"];
                switch ($type) {
                    case 'AliApp':
                        $code['pay_way'] = '支付宝APP支付';
                        break;
                    case 'AliWap':
                        $code['pay_way'] = '支付宝扫码支付';
                        break;
                    default:
                        # code...
                        break;
                }


                $order = Db::name('order_merchants')->where(['order_no' => $a[0]])->find();
                if ($order && $order['order_state'] == 'wait_pay') {
                    $code['order_state'] = 'wait_send';
                    $code['update_time'] = date("Y-m-d H:i:s", time());
                    $code['pay_time'] = date("Y-m-d H:i:s", time());
                    $code['ping_no'] = $_POST["trade_no"];   //ping++订单号
                    $code['pay_no'] = $_POST["out_trade_no"];
                    //$code['amount'] = $result['data']['object']['amount'] / 100;
                    $code['pay_charge'] = json_encode($_POST);
                    $result = Db::name('order_merchants')->where(['order_merchants_id' => $order['order_merchants_id']])->update($code);
                    $member = Db::name('member')->where(['member_id' => $order['member_id']])->find();
                    $order_goods = Db::name('order_goods')->where(['order_merchants_id' => $order['order_merchants_id']])->select();
                    foreach ($order_goods as $v) {
                        $goods = Db::name('Goods')->where(['goods_id' => $v['goods_id']])->find();
                        if ($goods) {
                            $merchant = Db::name('merchants')->where(['member_id' => $goods['member_id']])->find();
                            $goodsInfo['total_sales'] = $goods['total_sales'] + $v['goods_num'];
                            $goodsInfo['month_sales'] = $goods['month_sales'] + $v['goods_num'];
                            $goodsInfo['day_sales'] = $goods['day_sales'] + $v['goods_num'];
                            $merchantInfo['total_sales'] = $merchant['total_sales'] + $v['goods_num'];
                            $merchantInfo['month_sales'] = $merchant['month_sales'] + $v['goods_num'];
                            $merchantInfo['day_sales'] = $merchant['day_sales'] + $v['goods_num'];
                            Db::name('merchants')->where(['member_id' => $goods['member_id']])->update($merchantInfo);
                            if ($goods['goods_stock'] > $v['goods_num']) {
                                $goodsInfo['goods_stock'] = $goods['goods_stock'] - $v['goods_num'];
                                Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                                if ($v['specification_id']) {
                                    $specification = Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->find();
                                    if ($specification) {
                                        if ($specification['specification_stock'] > $v['goods_num']) {
                                            $goodsSpecification['specification_stock'] = $specification['specification_stock'] - $v['goods_num'];
                                        } else {
                                            $goodsSpecification['specification_stock'] = '0';
                                        }
                                        $goodsSpecification['specification_sales'] = $specification['specification_sales'] + $v['goods_num'];
                                    }
                                    Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->update($goodsSpecification);
                                }
                            } else {
                                $goodsInfo['goods_stock'] = '0';
                                Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                            }
                        }
                    }

                    //交易记录
                    $tradeRecord['member_id'] = $member['member_id'];
                    $tradeRecord['order_no'] = $a[0];
                    $tradeRecord['type'] = 1;
                    $tradeRecord['intime'] = date("Y-m-d H:i:s", time());
                    $tradeRecord['pay_no'] = $_POST["trade_no"];
                    $tradeRecord['amount'] = $_POST['total_amount'];
                    $tradeRecord['pay_return'] = json_encode($_POST);
                    Db::name('TradeRecord')->insert($tradeRecord);
                    $this->change_grade($member['member_id']);
                    echo "success"; //请不要修改或删除
                    success("支付成功");
                }else{
                    error('支付失败');
                }
            } else if (strpos($_POST['out_trade_no'], 'D') !== false) {   //待支付订单支付
                file_put_contents("callback.txt", "ddd", FILE_APPEND);
                $a = explode("D", $_POST["out_trade_no"]);
                $type = $_POST["subject"];
                switch ($type) {
                    case 'AliApp':
                        $code['pay_way'] = '支付宝APP支付';
                        break;
                    case 'AliWap':
                        $code['pay_way'] = '支付宝扫码支付';
                        break;
                    default:
                        # code...
                        break;
                }
                $order = Db::name('merchants_deposit_order')->where(['order_no' => $a[0]])->find();
                if ($order && $order['order_state'] == 'wait_pay') {
                    $code['order_state'] = 'end';
                    $code['update_time'] = date("Y-m-d H:i:s", time());
                    $code['pay_time'] = date("Y-m-d H:i:s", time());
                    //$code['amount'] = $result['data']['object']['amount'] / 100;
                    $code['pay_charge'] = json_encode($_POST);
                    Db::name('merchants_deposit_order')->where(['deposit_id' => $order['deposit_id']])->update($code);
                    Db::name('member')->where(['member_id' => $order['member_id']])->update(['type'=>'2']);
                    Db::name('merchants')->where(['member_id' => $order['member_id']])->update(['pay_state'=>'1']);
                    echo "success"; //请不要修改或删除
                    success("支付成功");
                } else {
                    error("支付失败");
                }
            }else {
                error("支付失败");
            }
        }else {
            //验证失败
            echo "fail";
        }

    }
    //--------------------------------------------
        public function alipayWapCallback()
    {   

        error_reporting(E_ALL);
        // file_put_contents("callback.txt", "\n\n", FILE_APPEND);
        // file_put_contents("callback.txt", $_POST, FILE_APPEND);
        // file_put_contents("callback.txt", "\n\n", FILE_APPEND);
        $t = "\n\n" . date("Y-m-d H:i:s", time()) . "\n" . var_export($_POST, true);

        $aop = new \AopClient;
        $aop->alipayrsaPublicKey = config('PUBLICKEY');
        $flag = $aop->rsaCheckV1($_POST, NULL, "RSA2");

        if($flag == 1 && $_POST['trade_status'] == 'TRADE_SUCCESS'){
            if (strpos($_POST['out_trade_no'], 'A') !== false) {     //确认订单支付
                $data['pay_state'] = 2;
                $data['pay_return'] = json_encode($_POST);
                $data['uptime'] = date("Y-m-d H:i:s", time());
                $a = explode("A", $_POST["out_trade_no"]);
                $record = Db::name('Recharge')->where(['pay_number' => $a[0]])->find();
                if($record && $record['pay_state'] == '1') {
                    $s = Db::name('Recharge')->where(['pay_number' => $a[0]])->update($data);
                    if ($s) {
                        $member = Db::name('member')->where(['member_id' => $record['member_id']])->find();
                        $money = $_POST['total_amount']; //支付金额
                        $diamond = $member['b_diamond'] + $record['meters'] + $record['zeng'];    //充值币相加
                        $this->insertDiamondRecord($member['member_id'], '1', '充值', $record['meters'], $record['zeng']);
                        Db::name('member')->where(['member_id' => $member['member_id']])->update(['b_diamond' => $diamond]);

                        //交易记录
                        $tradeRecord['member_id'] = $member['member_id'];
                        $tradeRecord['order_no'] = $a[0];
                        $tradeRecord['type'] = 2;
                        $tradeRecord['intime'] = date("Y-m-d H:i:s", time());
                        $tradeRecord['pay_no'] = $_POST["out_trade_no"];
                        $tradeRecord['amount'] = $money;
                        $tradeRecord['pay_return'] = json_encode($_POST);
                        Db::name('TradeRecord')->insert($tradeRecord);
                        $this->change_grade($member['member_id']);
                        echo "success"; //请不要修改或删除
                        success("支付成功");
                    } else {
                        error("支付失败");
                    }
                }
            } else if (strpos($_POST['out_trade_no'], 'B') !== false) {     //确认订单支付
                $a = explode("B", $_POST["out_trade_no"]);

                $type = $_POST["subject"];
                switch ($type) {
                    case 'AliApp':
                        $code['pay_way'] = '支付宝APP支付';
                        break;
                    case 'AliWap':
                        $code['pay_way'] = '支付宝扫码支付';
                        break;
                    default:
                        # code...
                        break;
                }

                $order = Db::name('order')->where(['order_no' => $a[0]])->find();
                if ($order && $order['order_state'] == 'wait_pay') {
                    $data['order_state'] = 'wait_send';
                    $data['uptime'] = date("Y-m-d H:i:s", time());
                    //$data['returns'] = json_encode($result);
                    $s = Db::name('order')->where(['order_no' => $a[0]])->update($data);
                    $ss = Db::name('order')->getLastSql();

                    if ($s) {
                        $code['order_state'] = 'wait_send';
                        $code['update_time'] = date("Y-m-d H:i:s", time());
                        $code['pay_time'] = date("Y-m-d H:i:s", time());
                        $code['ping_no'] = $_POST["trade_no"];   //ping++订单号
                        $code['pay_no'] = $_POST["out_trade_no"];
                        //$code['amount'] = $result['data']['object']['amount'] / 100;
                        $code['pay_charge'] = json_encode($_POST);
                        $result = Db::name('order_merchants')->where(['order_id' => $order['order_id']])->update($code);
                        $member = Db::name('member')->where(['member_id' => $order['member']])->find();
                        $order_goods = Db::name('order_goods')->where(['order_id' => $order['order_id']])->select();
                        foreach ($order_goods as $v) {
                            $goods = Db::name('goods')->where(['goods_id' => $v['goods_id']])->find();
                            if ($goods) {
                                $merchant = Db::name('merchants')->where(['member_id' => $goods['member_id']])->find();
                                $goodsInfo['total_sales'] = $goods['total_sales'] + $v['goods_num'];
                                $goodsInfo['month_sales'] = $goods['month_sales'] + $v['goods_num'];
                                $goodsInfo['day_sales'] = $goods['day_sales'] + $v['goods_num'];
                                $merchantInfo['total_sales'] = $merchant['total_sales'] + $v['goods_num'];
                                $merchantInfo['month_sales'] = $merchant['month_sales'] + $v['goods_num'];
                                $merchantInfo['day_sales'] = $merchant['day_sales'] + $v['goods_num'];
                                Db::name('merchants')->where(['member_id' => $goods['member_id']])->update($merchantInfo);
                                if ($goods['goods_stock'] > $v['goods_num']) {
                                    $goodsInfo['goods_stock'] = $goods['goods_stock'] - $v['goods_num'];
                                    Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                                    if ($v['specification_id']) {
                                        $specification = Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->find();
                                        if ($specification) {
                                            if ($specification['specification_stock'] > $v['goods_num']) {
                                                $goodsSpecification['specification_stock'] = $specification['specification_stock'] - $v['goods_num'];
                                            } else {
                                                $goodsSpecification['specification_stock'] = '0';
                                            }
                                            $goodsSpecification['specification_sales'] = $specification['specification_sales'] + $v['goods_num'];
                                        }
                                        Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->update($goodsSpecification);
                                    }
                                } else {
                                    $goodsInfo['goods_stock'] = '0';
                                    Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                                }
                            }
                        }
                        //交易记录
                        $tradeRecord['member_id'] = $member['member_id'];
                        $tradeRecord['order_no'] = $a[0];
                        $tradeRecord['type'] = 1;
                        $tradeRecord['intime'] = date("Y-m-d H:i:s", time());
                        $tradeRecord['pay_no'] = $_POST["out_trade_no"];
                        $tradeRecord['amount'] = $_POST['total_amount'];
                        $tradeRecord['pay_return'] = json_encode($_POST);
                        Db::name('TradeRecord')->insert($tradeRecord);
                        $this->change_grade($member['member_id']);
                        echo "success"; //请不要修改或删除
                        success("支付成功");
                    } else {
                        error("支付失败");
                    }
                }
            } else if (strpos($_POST['out_trade_no'], 'C') !== false) {   //待支付订单支付
                $a = explode("C", $_POST["out_trade_no"]);
                $type = $_POST["subject"];
                switch ($type) {
                    case 'AliApp':
                        $code['pay_way'] = '支付宝APP支付';
                        break;
                    case 'AliWap':
                        $code['pay_way'] = '支付宝扫码支付';
                        break;
                    default:
                        # code...
                        break;
                }


                $order = Db::name('order_merchants')->where(['order_no' => $a[0]])->find();
                if ($order && $order['order_state'] == 'wait_pay') {
                    $code['order_state'] = 'wait_send';
                    $code['update_time'] = date("Y-m-d H:i:s", time());
                    $code['pay_time'] = date("Y-m-d H:i:s", time());
                    $code['ping_no'] = $_POST["trade_no"];   //ping++订单号
                    $code['pay_no'] = $_POST["out_trade_no"];
                    //$code['amount'] = $result['data']['object']['amount'] / 100;
                    $code['pay_charge'] = json_encode($_POST);
                    $result = Db::name('order_merchants')->where(['order_merchants_id' => $order['order_merchants_id']])->update($code);
                    $member = Db::name('member')->where(['member_id' => $order['member']])->find();
                    $order_goods = Db::name('order_goods')->where(['order_merchants_id' => $order['order_merchants_id']])->select();
                    foreach ($order_goods as $v) {
                        $goods = Db::name('Goods')->where(['goods_id' => $v['goods_id']])->find();
                        if ($goods) {
                            $merchant = Db::name('merchants')->where(['member_id' => $goods['member_id']])->find();
                            $goodsInfo['total_sales'] = $goods['total_sales'] + $v['goods_num'];
                            $goodsInfo['month_sales'] = $goods['month_sales'] + $v['goods_num'];
                            $goodsInfo['day_sales'] = $goods['day_sales'] + $v['goods_num'];
                            $merchantInfo['total_sales'] = $merchant['total_sales'] + $v['goods_num'];
                            $merchantInfo['month_sales'] = $merchant['month_sales'] + $v['goods_num'];
                            $merchantInfo['day_sales'] = $merchant['day_sales'] + $v['goods_num'];
                            Db::name('merchants')->where(['member_id' => $goods['member_id']])->update($merchantInfo);
                            if ($goods['goods_stock'] > $v['goods_num']) {
                                $goodsInfo['goods_stock'] = $goods['goods_stock'] - $v['goods_num'];
                                Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                                if ($v['specification_id']) {
                                    $specification = Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->find();
                                    if ($specification) {
                                        if ($specification['specification_stock'] > $v['goods_num']) {
                                            $goodsSpecification['specification_stock'] = $specification['specification_stock'] - $v['goods_num'];
                                        } else {
                                            $goodsSpecification['specification_stock'] = '0';
                                        }
                                        $goodsSpecification['specification_sales'] = $specification['specification_sales'] + $v['goods_num'];
                                    }
                                    Db::name('goods_relation_specification')->where(['specification_id' => $v['specification_id']])->update($goodsSpecification);
                                }
                            } else {
                                $goodsInfo['goods_stock'] = '0';
                                Db::name('goods')->where(['goods_id' => $v['goods_id']])->update($goodsInfo);
                            }
                        }
                    }

                    //交易记录
                    $tradeRecord['member_id'] = $member['member_id'];
                    $tradeRecord['order_no'] = $a[0];
                    $tradeRecord['type'] = 1;
                    $tradeRecord['intime'] = date("Y-m-d H:i:s", time());
                    $tradeRecord['pay_no'] = $_POST["trade_no"];
                    $tradeRecord['amount'] = $_POST['total_amount'];
                    $tradeRecord['pay_return'] = json_encode($_POST);
                    Db::name('TradeRecord')->insert($tradeRecord);
                    $this->change_grade($member['member_id']);
                    echo "success"; //请不要修改或删除
                    success("支付成功");
                }else{
                    error('支付失败');
                }
            } else if (strpos($_POST['out_trade_no'], 'D') !== false) {   //待支付订单支付
                $a = explode("D", $_POST["out_trade_no"]);
                $type = $_POST["subject"];
                switch ($type) {
                    case 'AliApp':
                        $code['pay_way'] = '支付宝APP支付';
                        break;
                    case 'AliWap':
                        $code['pay_way'] = '支付宝扫码支付';
                        break;
                    default:
                        # code...
                        break;
                }
                $order = Db::name('merchants_deposit_order')->where(['order_no' => $a[0]])->find();
                if ($order && $order['order_state'] == 'wait_pay') {
                    $code['order_state'] = 'end';
                    $code['update_time'] = date("Y-m-d H:i:s", time());
                    $code['pay_time'] = date("Y-m-d H:i:s", time());
                    //$code['amount'] = $result['data']['object']['amount'] / 100;
                    $code['pay_charge'] = json_encode($_POST);
                    Db::name('merchants_deposit_order')->where(['deposit_id' => $order['deposit_id']])->update($code);
                    Db::name('member')->where(['member_id' => $order['member']])->update(['type'=>'2']);
                    Db::name('merchants')->where(['member_id' => $order['member']])->update(['pay_state'=>'1']);
                    echo "success"; //请不要修改或删除
                    success("支付成功");
                } else {
                    error("支付失败");
                }
            }else {
                error("支付失败");
            }

            // echo "success"; //请不要修改或删除
        }else {
            //验证失败
            echo "fail";
        }
    }

}

调用微信支付方法,支付宝不需要

<?php
namespace WeChatPay;
include 'Common.php';
include 'phpqrcode/phpqrcode.php';
Class WeChatPay extends Common{
    //********************************公共配置参数开始***************************************************//
    //支付请求地址
    const UNURL='https://api.mch.weixin.qq.com/pay/unifiedorder';
    //支付成功回调地址服务器回调地址
    const NOTIFY = 'http://www.test.com/api/pingxx/payCallback';
    //********************************公共配置参数结束***************************************************//
    //********************************app支付开放平台相关配置参数开始***************************************************//
    //微信开放平台的应用appid
    private $open_appid = '';
    //商户号(注册商户平台时,发置注册邮箱的商户id)
    private $open_mchid = '';
    //商户平台api支付处设置的key
    private $open_key = '';
    //*********************************app支付开放平台相关配置参数结束**************************************************//
    //*********************************微信公共好支付和扫码支付公共配置开始**************************************************//
    //商户API 密钥
    private $key = '';
    //公众号appID
    private $appid = '';
    //公众号AppSecret
    private $secret = '';
    //商户号id
    private $mchid = '';
    //*********************************微信公共好支付和扫码支付公共配置结束**************************************************//
    //生成支付所有的配置参数
    public function __construct(){
        //开放平台
        $this->open_appid= config('OPEN_APPId');
        $this->open_mchid= config('OPEN_MCHID');
        $this->open_key= config('OPEN_KEY');
        //公众号
        $this->appid= config('APPId');
        $this->mchid= config('MCHID');
        $this->key= config('KEY');
        $this->secret = config('SECRET');
    }
    //*****************************************APP支付生成统一订单************************************************/
    //微信App支付生成订单
    public function wechat_apppay($body, $out_trade_no, $total_fee){
        $datas["appid"] = $this->open_appid;
        $datas["body"] = $body;
        $datas["mch_id"] = $this->open_mchid;
        $datas["nonce_str"] = $this->getRandChar(32);
        $datas["notify_url"] = self::NOTIFY;
        $datas["out_trade_no"] = $out_trade_no;
        $datas["spbill_create_ip"] = $this->get_client_ip();
        $datas["total_fee"] = $total_fee;
        $datas["trade_type"] = "APP";
        //按照参数名ASCII字典序排序并且拼接API密钥生成签名
        $datas = $this->setSign($datas,$this->open_key);

        //配置xml最终得到最终发送的数据
        $xml = $this->ArrToXml($datas);

        $response = $this->postXmlCurl(self::UNURL,$xml);
        // print_r($response);exit;

        //将微信返回的结果xml转成数组
        $arr  = $this->XmlToArr($response);

        //app调起支付进行二次签名Ios
        $params = [
            'appid' => $this->open_appid,
            'partnerid' =>$this->open_mchid,
            'prepayid' => $arr['prepay_id'],
            'package' =>'Sign=WXPay',
            'noncestr' =>$this->getRandChar(32),
            'timestamp'=>strval(time()),
        ];
        $params = $this->setSign($params,$this->open_key);
        // echo json_encode($params);exit;
        $data = json_decode(json_encode($params),true);
        success($data);exit;
    }
    //*****************************************微信公众号统一生成订单************************************************/
    //微信公众号支付生成订单
    public function wechat_pubpay($body, $out_trade_no, $total_fee){
        /**
         * 1.构建原始数据
         * 2.加入签名
         * 3.将数据转换为XML
         * 4.发送XML格式的数据到接口地址
         */
        session_start();
        $params = [
            'appid' => $this->appid,
            'mch_id' => $this->mchid,
            'nonce_str' => $this->getRandChar(32),
            'body' => $body,
            'out_trade_no' => $out_trade_no,
            'total_fee' => $total_fee,
            'spbill_create_ip' => $this->get_client_ip(),
            'notify_url' => self::NOTIFY,
            'trade_type' => 'JSAPI',
            'openid' => $this->getOpenId($this->appid,$this->secret),
        ];
        //设置签名
        $params = $this->setSign($params,$this->key);
        //设置将数组转化成xml
        $xmldata = $this->ArrToXml($params);
        //写入log日志
        $resdata = $this->postXmlCurl(self::UNURL, $xmldata);
        $arr = $this->XmlToArr($resdata);
        //获取微信公众号支付需要的json数据
        $params = [
            'appId' => $this->appid,
            'timeStamp' =>strval(time()),
            'nonceStr' => md5(time()),
            'package' =>'prepay_id=' . $arr['prepay_id'],
            'signType' =>'MD5',
        ];
        ///进行签名
        $params['paySign'] = $this->getSign($params,$this->key);
        return json_encode($params);
    }
    //*****************************************微信扫码支付统一生成订单************************************************/
    //微信公众号支付生成订单
    /**
     * 1.获取二维码
     */
    public function wechat_getcode($out_trade_no){
        $params = [
            'appid'             => $this->appid,
            'mch_id'            => $this->mchid,
            'product_id'    => $out_trade_no,//订单号(产品ID)
            'time_stamp'    => time(),
            'nonce_str'     => md5(time()),
        ];
        $QRul =  'weixin://wxpay/bizpayurl?' . $this->arrToUrl($this->setSign($params,$this->key));
        success($QRul);

    }
    /**
     * 2.进行扫码支付
     */
    public function wechat_codepay($body, $out_trade_no, $total_fee){
        //调用统一下单API
        $params = [
            'appid'=> $this->appid,
            'mch_id'=> $this->mchid,
            'nonce_str'=>md5(time()),
            'body'=> $body,
            'out_trade_no'=> $out_trade_no,
            'total_fee'=> $total_fee,
            'spbill_create_ip'=>$this->get_client_ip(),
            'notify_url'=> self::NOTIFY,
            'trade_type'=>'NATIVE',
        ];
        //设置签名
        $params = $this->setSign($params,$this->key);
        //将数组转为xml
        $xml = $this->ArrToXml($params);
        //发送数据到统一下单API地址
        $response = $this->postXmlCurl(self::UNURL,$xml);
        $arr = $this->XmlToArr($response);
        if($arr['result_code'] == 'SUCCESS' && $arr['return_code'] == 'SUCCESS'){
            //获取扫码支付所需要的xml数据
            $return_params = [
                'return_code'  => 'SUCCESS',
                'appid'  => $this->appid,
                'mch_id'  => $this->mchid,
                'nonce_str'  => $this->getRandChar(32),
                'prepay_id'  => $arr['prepay_id'],
                'result_code'=> 'SUCCESS'
            ];
            //返回的xml
            $return_params = $this->setSign($return_params,$this->key);
            $return_xml = $this->ArrToXml($return_params);
            echo $return_xml;
        }else{
            $this->logs('error.txt', json_encode($arr));
            return false;
        }
    }
}

备注
支付宝回调需要在蚂蚁金服上配置。微信回调需要我们个人在代码写入

ENd
展开阅读全文

没有更多推荐了,返回首页