Selaa lähdekoodia

小程序退款

Your Name 3 kuukautta sitten
vanhempi
commit
347040e574
4 muutettua tiedostoa jossa 80 lisäystä ja 6 poistoa
  1. 7 3
      js/api.js
  2. 69 2
      pages/login/login.js
  3. 2 0
      pages/login/login.wxml
  4. 2 1
      project.private.config.json

+ 7 - 3
js/api.js

@@ -3,7 +3,7 @@ const SM4Exten = require('../js/SM4Exten');
 const miniprogramsm4 = require("../miniprogram_npm/miniprogram-sm-crypto/index").sm4;
 const secretId = "D2BCF8DE-AA24-4BF6-9C34-C8DD325E412B";//小程序应用ID
 const Secret = "6C680A47B87740138DFB299FC69A64E1";//小程序应用密钥
-const api_root = 'http://192.168.88.140:5006/'
+const api_root = 'http://192.168.5.5:5006/'
 const CurrentBuId = '12345678-9abc-def0-1234-56789abcdef0';
 
 function request(path, method = 'GET', data = null) {
@@ -193,7 +193,10 @@ function request_NozzleAuthorization(data) {
 function request_CancelNozzleAuthorization(data) {
   return request('api/Nozzle/CancelNozzleAuthorization?trxid=' +data, "GET",data);
 }
-
+//退款
+function request_RefundTrx(data) {
+  return request('api/Transactions/RefundTrx', "POST",data);
+}
 
 export default {
   request_GetSiteInfo,
@@ -201,5 +204,6 @@ export default {
   request_Wechatlogin,
   request_AddMiniprogramUser,
   request_NozzleAuthorization,
-  request_CancelNozzleAuthorization
+  request_CancelNozzleAuthorization,
+  request_RefundTrx
 }

+ 69 - 2
pages/login/login.js

@@ -67,9 +67,8 @@ Page({
 
   },
   pay(){
-    api.request_wechatPay(1)
+    api.request_wechatPay(23)
     .then(res => {
-      debugger
      wx.requestPayment({
        timeStamp: res.data.data.unifiedOrderResult.timeStamp,
        nonceStr: res.data.data.unifiedOrderResult.nonceStr,
@@ -106,6 +105,43 @@ Page({
      })
     });
   },
+  RefundTrx:function(e){
+    var RefundTrx = {
+      trxId : 31,
+      longitude :116.4074,
+      latitude:39.9042
+    };
+    api.request_RefundTrx(RefundTrx)
+    .then(res => {
+      debugger
+    });
+  },
+  handleGetPhoneNumber: function(e) {
+    if (e.detail.errMsg === 'getPhoneNumber:ok') {
+        // 用户同意授权,获取加密数据
+        const encryptedData = e.detail.encryptedData;
+        const iv = e.detail.iv;
+debugger
+        // 调用后端接口进行解密
+        wx.request({
+            url: 'https://your-backend-api-endpoint.com/decryptPhoneNumber', // 替换为你的后端API地址
+            method: 'POST',
+            data: {
+                encryptedData: encryptedData,
+                iv: iv,
+                sessionKey: 'your-session-key' // 替换为实际的session_key
+            },
+            success(res) {
+                console.log('解密后的手机号:', res.data);
+            },
+            fail(err) {
+                console.error('解密失败:', err);
+            }
+        });
+    } else {
+        console.log('用户拒绝授权');
+    }
+},
   handleAuthLogin() {
     console.log('一键授权登录按钮被点击');
     // 调用微信登录接口
@@ -149,5 +185,36 @@ Page({
         console.error('获取用户信息失败:', err);
       },
     });
+
+
+
+    wx.requestSubscribeMessage({
+      tmplIds: ['ldkKXfnHj-uKo6SBep08f_kaSjtxMOccJywHOEgxyPg'], // 最多支持3条
+      success(res) {
+        // 'accept'表示用户同意订阅该条id对应的模板消息
+        if (res['ldkKXfnHj-uKo6SBep08f_kaSjtxMOccJywHOEgxyPg'] === 'accept') {
+          // 用户同意订阅,调用云函数或服务器接口发送订阅消息
+          wx.cloud.callFunction({
+            name: 'sendSubscribeMessage',
+            data: {
+              templateId: '配置好的模板ID',
+              openid: 'o8pFb5fB9YROMFirFYrVNE3lr4ak',
+              data: {
+                thing1: {
+                  value: '活动名称'
+                },
+                // 其他参数...
+              }
+            },
+            success(res) {
+              console.log('订阅消息发送成功', res)
+            },   
+            fail(err) {
+              console.error('订阅消息发送失败', err)
+            }
+          })
+        }
+      }
+    })
   }
 })

+ 2 - 0
pages/login/login.wxml

@@ -6,6 +6,8 @@
   <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>
+    <button class="auth-button"   bindtap="RefundTrx">退款</button>
+    <button open-type="getPhoneNumber" bindgetphonenumber="handleGetPhoneNumber">获取手机号</button>
     <checkbox checked="{{true}}" disabled="{{true}}" />
     <text>我已阅读并同意</text>
     <text class="link">《用户协议》</text>

+ 2 - 1
project.private.config.json

@@ -4,5 +4,6 @@
   "setting": {
     "compileHotReLoad": true,
     "urlCheck": false
-  }
+  },
+  "libVersion": "3.7.7"
 }