From 4d4848ecda65adf399cd15a83049a4435e9a06c7 Mon Sep 17 00:00:00 2001
From: 石广澎 <shiguangpeng@163.com>
Date: 星期四, 08 八月 2024 11:35:21 +0800
Subject: [PATCH] feat(支付): 登录逻辑修噶

---
 pay/login.vue              |    9 ++
 common/http.interceptor.js |  118 +++++++++++++++++++++++---------------
 common/util.js             |    4 +
 main.js                    |    2 
 pay/scanpay.vue            |   12 +++-
 common/api/index.js        |    7 +
 6 files changed, 99 insertions(+), 53 deletions(-)

diff --git a/common/api/index.js b/common/api/index.js
index 5b1d247..35cafd9 100644
--- a/common/api/index.js
+++ b/common/api/index.js
@@ -20,12 +20,15 @@
 export const getOpenIdBase = (params, config = {}) => http.get(URL +
 	'/payfour-merchant/v1/web/aggregatePayAllin/getOpenIdBase', params, config = {});
 
-/*缁熶竴鐧诲綍*/
+/*缁熶竴鎺堟潈*/
 export const userLogin = (params, config = {}) => {
-	let path = '/payfour-merchant/v1/web/aggregatePayAllin/getOpenId'
+	let path = '/payfour-merchant/v1/web/aggregatePayAllin/getOpenId' //寰俊鎺堟潈
 	if(params.platform==5){ //鏀粯瀹濇巿鏉�
 		path = '/payfour-merchant/v1/web/h5PayAli/getUserIdByCode'
 	}
+	if (params.platform == 15) { //浜戦棯浠樻巿鏉�
+		path = '/service-merchant/v1/web/h5PayUnionPay/getUserIdByCode'
+	}
 	return http.get(URL + path,
 		params, config = {})
 };
diff --git a/common/http.interceptor.js b/common/http.interceptor.js
index 2a35602..9bef48b 100644
--- a/common/http.interceptor.js
+++ b/common/http.interceptor.js
@@ -1,53 +1,77 @@
 import {
-	ACCESSTOKEN,
-	config,
-	DEBUG
+    ACCESSTOKEN,
+    config,
+    DEBUG
 } from '@/common/config.js';
 import {
-	getPlat
+    getPlat
 } from 'common/util.js';
+
 module.exports = (vm) => {
-	uni.$u.http.setConfig((x) => {
-		return x = {
-			// baseURL: config.baseURL,
-			dataType: 'json',
-			timeout: 60000,
-			showLoading: false, //鏄惁鏄剧ず鍏ㄥ眬loading
-			timer: null,
-			loadingTime: 800, //澶氬皯绉掓棤杩斿洖鍐嶆樉绀簂oading
-			header: {
-				'Clientid': '944c6aade52ebbffc015478e6ce51b5a',
-				'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
-				'Access-Control-Allow-Origin': '*'
-			}
-		}
-	})
-	// 璇锋眰鎷︽埅
-	uni.$u.http.interceptors.request.use((x) => {
-		DEBUG && console.log('璇锋眰鍙傛暟', x);
-		// 寮曠敤token
-		const TOKEN = uni.getStorageSync(ACCESSTOKEN);
-		if (TOKEN) {
-			x.header[ACCESSTOKEN] = 'Bearer ' + TOKEN;
-		}
-		return x;
-	}, x => {
-		return Promise.reject(x)
-	})
-	// 鍝嶅簲鎷︽埅
-	uni.$u.http.interceptors.response.use((x) => {
-		DEBUG && console.log('杩斿洖缁撴灉', x);
-		let res = x.data
-		if (res.code == 10000) {
-			return res.data;
-		} else if (res.code == 10002) {
-			return Promise.reject(res)
-		} else {
-			vm.$u.toast(res.description || res.msg ||res.info || "璇锋眰寮傚父锛�"); //閿欒鎻愮ず淇℃伅
-			return Promise.reject(res)
-		}
-	}, (response) => {
-		vm.$u.toast("璇锋眰寮傚父锛�"); //閿欒鎻愮ず淇℃伅
-		return Promise.reject(response)
-	})
+    uni.$u.http.setConfig((x) => {
+        return x = {
+            // baseURL: config.baseURL,
+            dataType: 'json',
+            timeout: 60000,
+            showLoading: false, //鏄惁鏄剧ず鍏ㄥ眬loading
+            timer: null,
+            loadingTime: 800, //澶氬皯绉掓棤杩斿洖鍐嶆樉绀簂oading
+            header: {
+                'Clientid': '944c6aade52ebbffc015478e6ce51b5a',
+                'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
+                'Access-Control-Allow-Origin': '*'
+            }
+        }
+    })
+    // 璇锋眰鎷︽埅
+    uni.$u.http.interceptors.request.use((x) => {
+        DEBUG && console.log('璇锋眰鍙傛暟', x);
+        // 寮曠敤token
+        const TOKEN = uni.getStorageSync(ACCESSTOKEN);
+        if (TOKEN) {
+            x.header[ACCESSTOKEN] = 'Bearer ' + TOKEN;
+        }
+        const plat = getPlat()
+        if (plat == 2) { //寰俊
+            const OPENID = uni.getStorageSync('OPENID' + plat) || null
+            const UNIONID = uni.getStorageSync('UNIONID' + plat) || null
+            if (OPENID) {
+                x.header['Openid'] = OPENID;
+            }
+            if (UNIONID) {
+                x.header['Unionid'] = UNIONID;
+            }
+        }
+        if (plat == 5) { //鏀粯瀹�
+            const ALIUSERID = uni.getStorageSync('ALIUSERID' + plat) || null
+            if (ALIUSERID) {
+                x.header['Aliuserid'] = ALIUSERID;
+            }
+        }
+        if (plat == 15) { //浜戦棯浠�
+            const UNIONPAYID = uni.getStorageSync('UNIONPAYID ' + plat) || null
+            if (UNIONPAYID) {
+                x.header['Unionpayid '] = UNIONPAYID;
+            }
+        }
+        return x;
+    }, x => {
+        return Promise.reject(x)
+    })
+    // 鍝嶅簲鎷︽埅
+    uni.$u.http.interceptors.response.use((x) => {
+        DEBUG && console.log('杩斿洖缁撴灉', x);
+        let res = x.data
+        if (res.code == 10000) {
+            return res.data;
+        } else if (res.code == 10002) {
+            return Promise.reject(res)
+        } else {
+            vm.$u.toast(res.description || res.msg || res.info || "璇锋眰寮傚父锛�"); //閿欒鎻愮ず淇℃伅
+            return Promise.reject(res)
+        }
+    }, (response) => {
+        vm.$u.toast("璇锋眰寮傚父锛�"); //閿欒鎻愮ず淇℃伅
+        return Promise.reject(response)
+    })
 }
diff --git a/common/util.js b/common/util.js
index f345d22..f4784b7 100644
--- a/common/util.js
+++ b/common/util.js
@@ -836,6 +836,10 @@
     if (ua.match(/AlipayClient/i) == 'alipayclient') {
         return 5;
     }
+    //鍒ゆ柇鏄笉鏄簯闂粯
+    if (ua.indexOf('unionpay/1.0') !== -1) {
+        return 15;
+    }
     // #endif
     // #ifdef MP-WEIXIN
     return 2;
diff --git a/main.js b/main.js
index aab8204..72ef9f7 100644
--- a/main.js
+++ b/main.js
@@ -1,5 +1,7 @@
 import App from './App'
 import Vue from 'vue'
+import Vconsole from 'vconsole';
+new Vconsole();
 import uView from '@/uni_modules/uview-ui'
 Vue.use(uView)
 
diff --git a/pay/login.vue b/pay/login.vue
index 402ceac..5c6fee4 100644
--- a/pay/login.vue
+++ b/pay/login.vue
@@ -20,7 +20,11 @@
 		},
     onShow() {
       let redirect_uri = `${config.webURL}/pay/scanpay?cid=${this.opt.cid||''}&shopId=${this.opt.shopId||''}&activityQrcodeId=${this.opt.activityQrcodeId||''}&smoney=${this.opt.smoney||''}`
-      if(uni.getStorageSync('OPENID'+this.platform)){
+      if(this.platform==2&&uni.getStorageSync('OPENID'+this.platform)){
+        window.location.href = redirect_uri
+        return
+      }
+      if(this.platform==5&&uni.getStorageSync('ALIUSERID'+this.platform)){
         window.location.href = redirect_uri
         return
       }
@@ -31,6 +35,9 @@
       } else if (this.platform == 5) {
         window.location.href =
             `https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=${config.ali_appid}&scope=auth_base&redirect_uri=${redirect_uri}&state=STATE`
+      } else if (this.platform == 15) {
+        window.location.href =
+            `https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl=${redirect_uri}`
       } else {
         uni.reLaunch({
           url: `/pay/scanpay?cid=${this.opt.cid}`
diff --git a/pay/scanpay.vue b/pay/scanpay.vue
index 618c577..84d955b 100644
--- a/pay/scanpay.vue
+++ b/pay/scanpay.vue
@@ -228,16 +228,19 @@
       this.cid = opt.cid
       this.init()
     }
-    if (opt.code || opt.auth_code) {
+    if (opt.code || opt.auth_code || opt.userAuthCode) {
       let params = {
         code: opt.code
       }
       let code = opt.code
-      if (this.payWay == 2&&opt.state == 1 ) {
+      if (this.payWay == 2&&opt.state == 1 ) { //寰俊
         params.getUserInfo = 1
       }
-      if (this.payWay == 5) {
+      if (this.payWay == 5) { //鏀粯瀹�
         params.code = opt.auth_code
+      }
+      if (this.payWay == 15) { //浜戦棯浠�
+        code = opt.userAuthCode
       }
       const cd = uni.getStorageSync('cd')
       if (code === cd) {
@@ -290,6 +293,9 @@
       if (res.unionid) {
         uni.setStorageSync('UNIONID' + this.payWay, res.unionid)
       }
+      if (res.aLiUserId) {
+        uni.setStorageSync('ALIUSERID' + this.payWay, res.aLiUserId)
+      }
       this.UNIONID = res.unionid
       uni.setStorageSync(ACCESSTOKEN, res.token)
       uni.setStorageSync('IS_NEW', res.isNew)

--
Gitblit v1.9.1