当前位置:   article > 正文

PHP实现小程序微信支付(v3版本)_php 微信小程序支付

php 微信小程序支付

PS:本篇文章是PHP对小程序进行微信支付v3版本的实现,仅用于对支付流程的了解,具体使用方面需要大家自行调整

小程序端JS代码:

getPrepayID(){
   
    var that = this
    wx.getStorage({
   
      key:'openid',
      success(res){
   
        that.setData({
   
          'openid':res.data
        })
      }
    })
    wx.getStorage({
   
      key:'username',
      success(res){
   
        that.setData({
   
          'username':res.data
        })
      }
    })
    //console.log(that.data.openid)
    wx.request({
   
      url: 'http://127.0.0.1:2908/wxPayV3/v3GetPrepayId.php', //此处填写你的PHP文件url地址
      method:'POST',
      header:{
   
        'content-type':'application/x-www-form-urlencoded'
      },
      data:{
     //发送的数据,大家根据需要自行调整
        'description':'0.38mm.pen',  //商品描述,自行调整
        'openid':that.data.openid,  //用户openid,此处是从缓存中获取到的
        'total':1,                  //订单总金额,单位为分,实际使用请乘100改为以元为单位
        'username':that.data.username,  //用户的昵称,此处从缓存中获取,用于后续存放于数据库中
        'goods_id':1                //商品编号,数据库使用
      },
      success(res){
   
        //console.log(res)
       // that.setData({
   
       //   'nonceStr':res.data.nonceStr,
       //   'package':res.data.package,
       //   'paySign':res.data.paySign,
       //   'timeStamp':res.data.timeStamp,
       //   'signType':res.data.signType
       // })
        console.log(res.data)
        wx.requestPayment({
   
          nonceStr: res.data.nonceStr,
          package: res.data.package,
          paySign: res.data.paySign,
          timeStamp: res.data.timeStamp,
          signType: 'RSA',
          success(res){
   
				//自行书写成功调用的逻辑,本篇仅为了实现成功支付
          }
        })
      }
    })
  },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69

PHP类的相关代码:

<?php
require_once('../config/appConfig.php');  //读取相关配置,主要是appid,mch_id,serial_no,APIv3

class API_v3Connect
{
   
    /**
     * 获取相关配置
     */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/132330
推荐阅读
相关标签
  

闽ICP备14008679号