• 小程序php支付,前后端分离


    小程序端:

    xml:

    <button type="default" bindtap="payOrder">支付</button>
    js:
    payOrder: function (event) {
    wx.request({
    url: 'http://test.dailingmei.com/api/Mini/miniGetPayMoney',
    data: { //发送给后台的数据
    token: wx.getStorageSync('token'),
    order_list_id: "88"
    },
    header: { //请求头
    'content-type': 'application/x-www-form-urlencoded'
    },
    method: "POST", //get为默认方法/POST
    success: function (res) {
    console.log(res);
    wx.requestPayment({
    timeStamp: res.data.data.result.timeStamp,
    nonceStr: res.data.data.result.nonceStr,
    package: res.data.data.result.package,
    signType: 'MD5',
    paySign: res.data.data.result.paySign,
    success: function (res) {
    // success
    console.log(res);
    },
    fail: function (res) {
    // fail
    console.log(res);
    },
    complete: function (res) {
    // complete
    console.log(res);
    }
    })
    },
    fail: function (err) { }, //请求失败
    complete: function () { } //请求完成后执行的函数
    })
    },
     
    后台:
    use thinkConfig;
    use YansongdaPayPay;
    use YansongdaPayLog;

    public function miniGetPayMoney(){
    if ($this->request->isPost()) {
    $validate = new hinkValidate(['order_list_id'=>'require']);
    $request_data = $this->request->param();
    $check_result = $validate->check($request_data);
    if($check_result == true){
    $order_list_model = new appapimodelorderOrderlist;
    $price = $order_list_model->calculatePrice($request_data['order_list_id']);
    $price *= 100;
    $user_info = $this->auth->getUserinfo();
    $user_id = $user_info['id'];
    $out_trade_no = $user_id . '-' . time();
    $order = [
    'out_trade_no' => $out_trade_no,
    'body' => '商品支付',
    'total_fee' => $price,
    'openid' => $this->auth->getUser()->openid,
    ];
    $result = Pay::wechat(Config::get('wechat.pay'))->miniapp($order);
    appapimodelpayOrder::create(
    [
    'package' => $out_trade_no,
    'order_type' => 'order',
    'order_mes' => $request_data['order_list_id']
    ]
    );
    $this->success('success', ['order_list_id'=>$request_data['order_list_id'],'money'=>$price,'result'=>$result]);
    }else{
    $this->error('没传订单编号');
    }
    }
    $this->error('提交方式不是POST');
    }
  • 相关阅读:
    Notes of the scrum meeting(12.7)
    Notes of the scrum meeting(12.5)
    事后分析报告(M1阶段)
    锁屏软件发布说明
    Android 锁屏软件MemoryDebris测试报告
    锁屏软件功能介绍
    Notes of the scrum meeting(11/4)
    Notes of the scrum meeting(11/3)
    Notes of the scrum meeting(11/2)
    SCRUM 12.17
  • 原文地址:https://www.cnblogs.com/daochong/p/10195866.html
Copyright © 2020-2023  润新知