微信小程序支付前端源码
网络编程 2021-07-04 16:46www.168986.cn编程入门
这篇文章主要为大家详细介绍了微信小程序支付前端源码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了微信小程序支付前端源码,供大家参考,具体内容如下
//index.js Page({ data: { }, //点击支付按钮进行支付 payclick: function () { var t = this; wx.login({ //获取code换取openID suess: function (res) { //code = res.code //返回code console.log("获取code"); console.log(res.code); var opid = t.getOpenId(res.code); } }) }, //获取openID getOpenId: function (code) { var that = this; wx.request({ url: "https://api.weixin.qq./sns/jscode2session?appid=你的appid&secret=AppSecret(小程序密钥)&js_code=" + code + "&grant_type=authorization_code", data: {}, method: 'GET', suess: function (res) { console.log("获取openid") console.log(res) that.setData({ openid: res.data.openid, session_key: res.data.session_key }) that.generateOrder(res.data.openid) }, fail: function () { // fail }, plete: function () { // plete } }) }, //生成商户订单 generateOrder: function (openid) { var that = this wx.request({ url: 'http://localhost:25492/wx/getda',//后台请求地址 method: 'GET', data: { gfee: '商品价钱', gname: '商品名称', openId: openid //(商品价钱和商品名称根据自身需要是否传值, openid为必传) }, suess: function (res) { console.log("后台获取数据成功"); console.log(res); var param = { "timeStamp": res.data.timeStamp, "package": res.data.package, "paySign": res.data.paySign, "signType": "MD5", "nonceStr": res.data.nonceStr }; //发起支付 that.pay(param); }, fail: function (res) { console.log("向后台发送数据失败") } }) }, //支付 pay: function (param) { var that = this; console.log("发起支付") console.log(param) wx.requestPayment({ timeStamp: param.timeStamp, nonceStr: param.nonceStr, package: param.package, signType: param.signType, paySign: param.paySign, suess: function (res) { console.log("suess"); console.log(res); }, fail: function (res) { console.log("fail") console.log(res); }, plete: function (res) { console.log("plete"); console.log(res) } }) } })
本地调试如过出现请求失败请将 微信开发者工具 > 详情(右上角) > 不校验合法域名、web-view(业务域名)、TLS 版本以及 HTTPS 证书 勾上即可
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
上一篇:浅谈Vue.use的使用
下一篇:微信小程序使用swiper组件实现类3D轮播图
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程