Bläddra i källkod

Merge branch 'master' of http://dev.hsfuel.com:3000/wei.chen/Fuelwx into feature/整合页面与接口

# Conflicts:
#	project.config.json
Zhenghanjv 3 månader sedan
förälder
incheckning
68ef234630
4 ändrade filer med 55 tillägg och 45 borttagningar
  1. 9 4
      js/api.js
  2. 44 39
      pages/login/login.js
  3. 1 0
      pages/login/login.wxml
  4. 1 2
      project.config.json

+ 9 - 4
js/api.js

@@ -7,7 +7,7 @@ const api_root = 'http://192.168.0.202:5006/'
 const CurrentBuId = '12345678-9abc-def0-1234-56789abcdef0';
 
 function request(path, method = 'GET', data = null) {
-
+  var WachatID = wx.getStorageSync('WachatID')
   return new Promise((resolve, reject) => { 
     var sign_method = "HMAC_SM4";
     var url = api_root +  path;
@@ -35,7 +35,8 @@ function request(path, method = 'GET', data = null) {
         "nonce": nonce,
         "timestamp": timestamp,
         "signature": signature,
-        "CurrentBuId" : CurrentBuId
+        "CurrentBuId" : CurrentBuId,
+        "WachatID":WachatID
       },
       url: url, 
       method: method,
@@ -169,8 +170,12 @@ function request_GetMiniProgramTransactionsUnpaidQuery(data) {
 function request_GetMiniProgramTransactionsUnpaidNozzle(data) {
   return request('api/Transactions/GetMiniProgramTransactionsUnpaidNozzle', "GET",data);
 }
-
+//小程序登录
+function request_Wechatlogin(data) {
+  return request('api/Auth/Wechatlogin?code='+ data, "GET",data);
+}
 export default {
   request_getSite,
-  request_wechatPay
+  request_wechatPay,
+  request_Wechatlogin
 }

+ 44 - 39
pages/login/login.js

@@ -65,53 +65,58 @@ Page({
    */
   onShareAppMessage() {
 
+  },
+  pay(){
+    api.request_wechatPay(1)
+    .then(res => {
+     wx.requestPayment({
+       timeStamp: res.data.data.unifiedOrderResult.timeStamp,
+       nonceStr: res.data.data.unifiedOrderResult.nonceStr,
+       package: res.data.data.unifiedOrderResult.package,
+       signType: res.data.data.unifiedOrderResult.signType,
+       paySign: res.data.data.unifiedOrderResult.paySign,
+       success: res => {
+         wx.hideLoading()
+         wx.showToast({
+           title: '支付成功!',
+         })
+         setTimeout(function () {
+           wx.switchTab({
+             url: '../index/index',
+           })
+         }, 2000)
+
+       },
+       fail: res => {
+         wx.hideLoading()
+         wx.showModal({
+           title: '支付失败',
+           content: res.errMsg + '请稍后再试',
+           showCancel: false,
+           success(res) {
+             if (res.confirm) {
+               wx.switchTab({
+                 url: '../home/home',
+               })
+             }
+           }
+         })
+       }
+     })
+    });
   },
   handleAuthLogin() {
     console.log('一键授权登录按钮被点击');
-     api.request_wechatPay(1)
-     .then(res => {
-      wx.requestPayment({
-        timeStamp: res.data.data.unifiedOrderResult.timeStamp,
-        nonceStr: res.data.data.unifiedOrderResult.nonceStr,
-        package: res.data.data.unifiedOrderResult.package,
-        signType: res.data.data.unifiedOrderResult.signType,
-        paySign: res.data.data.unifiedOrderResult.paySign,
-        success: res => {
-          wx.hideLoading()
-          wx.showToast({
-            title: '支付成功!',
-          })
-          setTimeout(function () {
-            wx.switchTab({
-              url: '../index/index',
-            })
-          }, 2000)
-
-        },
-        fail: res => {
-          wx.hideLoading()
-          wx.showModal({
-            title: '支付失败',
-            content: res.errMsg + '请稍后再试',
-            showCancel: false,
-            success(res) {
-              if (res.confirm) {
-                wx.switchTab({
-                  url: '../home/home',
-                })
-              }
-            }
-          })
-        }
-      })
-     });
     // 调用微信登录接口
     wx.login({
       success(res) {
         if (res.code) {
           console.log('登录成功,code:', res.code);
-          // 将 code 发送到服务器,获取用户信息
-          // 例如:wx.request({ url: 'https://example.com/login', data: { code: res.code } })
+          api.request_Wechatlogin(res.code)
+          .then(res => {
+            debugger
+            wx.setStorageSync('WachatID', res.data.data)
+          });
         } else {
           console.log('登录失败:', res.errMsg);
         }

+ 1 - 0
pages/login/login.wxml

@@ -5,6 +5,7 @@
   <view class="action-text">立码加油</view>
   <button class="auth-button" style="width: 547rpx; height: 94rpx; display: block; box-sizing: border-box; left: 0rpx; top: 0rpx"  bindtap="handleAuthLogin">一键授权登录</button>
   <view class="agreement">
+    <button class="auth-button"   bindtap="pay">支付</button>
     <checkbox checked="{{true}}" disabled="{{true}}" />
     <text>我已阅读并同意</text>
     <text class="link">《用户协议》</text>

+ 1 - 2
project.config.json

@@ -24,6 +24,5 @@
     "tabIndent": "auto",
     "tabSize": 2
   },
-  "appid": "wxb198dafff060e651",
-  "projectname": "fuelwx"
+  "appid": "wx32dbc8c959199561"
 }