parent
							
								
									bff8bd8dd0
								
							
						
					
					
						commit
						6316405712
					
				|  | @ -9,7 +9,9 @@ export function getSpuList(recommendType) { | |||
| 
 | ||||
| // 获得商品 SPU 分页
 | ||||
| export function getSpuPage(data) { | ||||
|   return request.get('app-api/product/spu/page', data); | ||||
|   return request.get('app-api/product/spu/page', data, { | ||||
|     noAuth: true // TODO 芋艿:后续要做调整
 | ||||
|   }); | ||||
| } | ||||
| 
 | ||||
| // 查询商品
 | ||||
|  |  | |||
|  | @ -0,0 +1,8 @@ | |||
| import request from "@/utils/request.js"; | ||||
| 
 | ||||
| // 创建微信 JS SDK 初始化所需的签名
 | ||||
| export function createJsapiSignature(url) { | ||||
|   return request.post("app-api/system/wx-mp/create-jsapi-signature?url=" + url, {}, { | ||||
|     noAuth: true // TODO 芋艿:后续要做调整
 | ||||
|   }); | ||||
| } | ||||
|  | @ -3,9 +3,9 @@ import WechatJSSDK from "@/plugin/jweixin-module/index.js"; | |||
| 
 | ||||
| 
 | ||||
| import { | ||||
| 	getWechatConfig, | ||||
| 	wechatAuth | ||||
| } from "@/api/public"; | ||||
| import * as WeiXinApi from '@/api/system/weixin.js'; | ||||
| import { | ||||
| 	WX_AUTH, | ||||
| 	STATE_KEY, | ||||
|  | @ -21,44 +21,30 @@ import Cache from '@/utils/cache'; | |||
| class AuthWechat { | ||||
| 
 | ||||
| 	constructor() { | ||||
| 		//微信实例化对象
 | ||||
| 		this.instance = WechatJSSDK; | ||||
| 		//是否实例化
 | ||||
| 		this.status = false; | ||||
| 
 | ||||
| 		this.instance = WechatJSSDK; // 微信实例化对象
 | ||||
| 		this.status = false; // 是否实例化
 | ||||
| 		this.initConfig = {}; | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	isAndroid(){ | ||||
| 		let u = navigator.userAgent; | ||||
| 		return u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; | ||||
| 	} | ||||
| 	 | ||||
| 	signLink() { | ||||
| 		if (typeof window.entryUrl === 'undefined' || window.entryUrl === '') { | ||||
| 			  	window.entryUrl = location.href.split('#')[0] | ||||
| 			} | ||||
| 		return  /(Android)/i.test(navigator.userAgent) ? location.href.split('#')[0] : window.entryUrl; | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * 初始化wechat(分享配置) | ||||
| 	 * 初始化 wechat(分享配置) | ||||
| 	 */ | ||||
| 	wechat() { | ||||
| 		return new Promise((resolve, reject) => { | ||||
| 			// if (this.status && !this.isAndroid()) return resolve(this.instance);
 | ||||
| 			getWechatConfig() | ||||
| 				.then(res => { | ||||
| 					this.instance.config(res.data); | ||||
| 					this.initConfig = res.data; | ||||
| 			// if (this.status) return resolve(this.instance);
 | ||||
|       WeiXinApi.createJsapiSignature(location.href).then(res => { | ||||
|         // debugger
 | ||||
|         const jsapiTicket = res.data; | ||||
|         jsapiTicket.jsApiList = ['chooseWXPay']; // TODO  芋艿:这里要设置下
 | ||||
|         jsapiTicket.debug = false; | ||||
|         this.instance.config(jsapiTicket); | ||||
|         this.initConfig = jsapiTicket; | ||||
|         this.status = true; | ||||
|         this.instance.ready(() => { | ||||
|           resolve(this.instance); | ||||
|         }) | ||||
|       }).catch(err => { | ||||
| 					console.log('微信分享配置失败',err); | ||||
|         console.log('WechatJSSDK 初始化失败 ',err); | ||||
|         this.status = false; | ||||
|         reject(err); | ||||
|       }); | ||||
|  | @ -169,6 +155,10 @@ class AuthWechat { | |||
| 	 * 自动去授权 | ||||
| 	 */ | ||||
| 	oAuth(snsapiBase,url) { | ||||
|     // TODO 芋艿:先链式去掉这个逻辑;
 | ||||
|     if (true) { | ||||
|       return; | ||||
|     } | ||||
| 		if (uni.getStorageSync(WX_AUTH) && store.state.app.token && snsapiBase == 'snsapi_base') return; | ||||
| 		const { | ||||
| 			code | ||||
|  | @ -201,10 +191,6 @@ class AuthWechat { | |||
| 		// }
 | ||||
| 	} | ||||
| 
 | ||||
| 	clearAuthStatus() { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * 授权登录获取token | ||||
| 	 * @param {Object} code | ||||
|  |  | |||
|  | @ -91,7 +91,8 @@ | |||
|     }, | ||||
|     "h5" : { | ||||
|         "devServer" : { | ||||
|             "https" : false | ||||
|             "https" : false, | ||||
|             "disableHostCheck": true | ||||
|         }, | ||||
|         "router" : { | ||||
|             "mode" : "history", | ||||
|  |  | |||
|  | @ -107,7 +107,6 @@ | |||
| 					title: '加载订单中' | ||||
| 				}); | ||||
|         PayOrderApi.getOrder(this.orderId).then(res => { | ||||
|           // TODO 芋艿:如果已支付,则跳转回 | ||||
|           if (res.data.status === 10) { | ||||
|             uni.showToast({ | ||||
|               title: '支付成功' | ||||
|  | @ -166,6 +165,9 @@ | |||
|           channelCode: channelCode, | ||||
|           displayMode: 'url', // TODO 芋艿:后续可以优化 | ||||
|           returnUrl: this.getPayReturnUrl(), | ||||
|           channelExtras: { | ||||
|             openid: "ockUAwIZ-0OeMZl9ogcZ4ILrGba0" | ||||
|           } | ||||
| 				}).then(res => { | ||||
|           this.handleSubmitOrderResult(res.data); | ||||
| 
 | ||||
|  | @ -245,29 +247,7 @@ | |||
| 							}) | ||||
| 							// #endif | ||||
| 							// #ifdef H5 | ||||
| 							this.$wechat.pay(res.data.result.jsConfig).then(res => { | ||||
| 								return that.$util.Tips({ | ||||
| 									title: '支付成功', | ||||
| 									icon: 'success' | ||||
| 								}, { | ||||
| 									tab: 5, | ||||
| 									url: goPages | ||||
| 								}); | ||||
| 							}).catch(res => { | ||||
| 								if (!this.$wechat.isWeixin()) { | ||||
| 									uni.redirectTo({ | ||||
| 										url: goPages + '&msg=' + that.$t(`支付失败`) + | ||||
| 											'&status=2' | ||||
| 										// '&msg=支付失败&status=2' | ||||
| 									}) | ||||
| 								} | ||||
| 								if (res.errMsg == 'chooseWXPay:cancel') return that.$util.Tips({ | ||||
| 									title: '取消支付' | ||||
| 								}, { | ||||
| 									tab: 5, | ||||
| 									url: goPages + '&status=2' | ||||
| 								}); | ||||
| 							}) | ||||
| 							    // 已删除,已经实现; | ||||
| 							// #endif | ||||
| 							// #ifdef APP-PLUS | ||||
| 							uni.requestPayment({ | ||||
|  | @ -409,7 +389,52 @@ | |||
|           window.location = displayContent; | ||||
|           return; | ||||
|         } | ||||
|         // 2.2 | ||||
|         // 2.2 如果返回的是 CUSTOM,则自定义处理 | ||||
|         if (displayMode === 'custom') { | ||||
|           if (this.channelCode === 'wx_pub') { | ||||
|             this.handleSubmitOrderResultForWxPub(displayContent) | ||||
|             return; | ||||
|           } | ||||
|         } | ||||
|       }, | ||||
|       /** | ||||
|        * 发起微信公众号支付 | ||||
|        */ | ||||
|       handleSubmitOrderResultForWxPub(displayContent) { | ||||
|         const payConfig = JSON.parse(displayContent); | ||||
|         this.$wechat.pay({ | ||||
|           timestamp: payConfig.timeStamp, | ||||
|           nonceStr: payConfig.nonceStr, | ||||
|           package: payConfig.packageValue, | ||||
|           signType: payConfig.signType, | ||||
|           paySign: payConfig.paySign, | ||||
|         }).then(res => { | ||||
|           // 失败的情况 | ||||
|           if (res.errMsg === 'chooseWXPay:cancel') { | ||||
|             return this.$util.Tips({ | ||||
|               title: '取消微信支付' | ||||
|             }); | ||||
|           } | ||||
|           if (res.errMsg) { | ||||
|             return this.$util.Tips({ | ||||
|               title: res.errMsg, | ||||
|               icon: 'error' | ||||
|             }) | ||||
|           } | ||||
| 
 | ||||
|           // 成功的情况 | ||||
|           return this.$util.Tips({ | ||||
|             title: '支付成功', | ||||
|             icon: 'success' | ||||
|           }, () => { | ||||
|             this.goReturnUrl('success'); | ||||
|           }); | ||||
|         }).catch(res => { | ||||
|           return this.$util.Tips({ | ||||
|             title: '初始化微信支付失败,请重试或者选择其它支付方式', | ||||
|             icon: 'error' | ||||
|           }) | ||||
|         }) | ||||
|       }, | ||||
| 
 | ||||
|       /** | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 YunaiV
						YunaiV