マイクロクレジットカード決済機能(先端)の実現
2739 ワード
マイクロクレジットカード決済機能(先端)の実現
var app = getApp();
2 Page({
3 data: {},
4 onLoad: function (options) {
5 // options
6 var that = this
7 // code
8 wx.login({
9 success: function (res) {
10 console.log(res.code)
11 // openid
12 that.getOpenId(res.code)
13 }
14 });
15 },
16 getOpenId: function (code) {
17 var that = this;
18 wx.request({
19 url: "https://api.weixin.qq.com/sns/jscode2session?appid= appid&secret= &js_code=" + code + "&grant_type=authorization_code",
20 data: {},
21 method: 'GET',
22 success: function (res) {
23 that.generateOrder(res.data.openid)
24 },
25 fail: function () {
26 // fail
27 },
28 complete: function () {
29 // complete
30 }
31 })
32 },
33 /** */
34 generateOrder: function (openid) {
35 var that = this
36 //
37 wx.request({
38 url: ' ',
39 method: 'GET',
40 data: {
41 gfee: ' ',
42 gname: ' ',
43 openId:openid
44 ( ,openid )
45 },
46 success: function (res) {
47 var pay = res.data
48 //
49 var timeStamp = pay[0].timeStamp;
50 var packages = pay[0].package;
51 var paySign = pay[0].paySign;
52 var nonceStr = pay[0].nonceStr;
53 var param = { "timeStamp": timeStamp, "package": packages, "paySign": paySign, "signType": "MD5", "nonceStr": nonceStr };
54 that.pay(param)
55 },
56 })
57 },
58
59 /* */
60 pay: function (param) {
61 console.log(" ")
62 console.log(param)
63 wx.requestPayment({
64 timeStamp: param.timeStamp,
65 nonceStr: param.nonceStr,
66 package: param.package,
67 signType: param.signType,
68 paySign: param.paySign,
69 success: function (res) {
70 // success
71 wx.navigateBack({
72 delta: 1, // delta( 1)
73 success: function (res) {
74 wx.showToast({
75 title: ' ',
76 icon: 'success',
77 duration: 2000
78 })
79 },
80 fail: function () {
81 // fail
82
83 },
84 complete: function () {
85 // complete
86 }
87 })
88 },
89 fail: function (res) {
90 // fail
91 },
92 complete: function () {
93 // complete
94 }
95 })
96 }
97 })