Parcourir la source

安卓手机没有安装应用跳转到谷歌商店

qmj dans 3 heures
Parent
commit
2b8747f772

+ 4 - 4
main.js

@@ -36,10 +36,10 @@ Vue.prototype.$formPr = function(price) {
 };
 
 
-Vue.prototype.$baseImagurl = 'https://backend.cityexpress168.com.vn/prod-api'; //生产环境
-Vue.prototype.$upImagurl = 'https://api.cityexpress168.com.vn/utils/Upload'; //生产环境
-// Vue.prototype.$baseImagurl = 'https://ctebackend.waimai-paotui.com/prod-api'; //预发布
-// Vue.prototype.$upImagurl = 'https://cteapi.waimai-paotui.com/utils/Upload'; //预发布
+// Vue.prototype.$baseImagurl = 'https://backend.cityexpress168.com.vn/prod-api'; //生产环境
+// Vue.prototype.$upImagurl = 'https://api.cityexpress168.com.vn/utils/Upload'; //生产环境
+Vue.prototype.$baseImagurl = 'https://ctebackend.waimai-paotui.com/prod-api'; //预发布
+Vue.prototype.$upImagurl = 'https://cteapi.waimai-paotui.com/utils/Upload'; //预发布
 
 const goEasy = GoEasy.getInstance({
 	host: "singapore.goeasy.io", //若是新加坡区域:singapore.goeasy.io

+ 65 - 7
pages/shanpinxungou/shangjia/shangjiaView.vue

@@ -248,6 +248,7 @@
 				downloadUrls: {},
 				isShangjia: 0,
 				id: 0,
+				androidPackageName: '', // 安卓应用包名
 			}
 		},
 		onShow() {
@@ -378,6 +379,10 @@
 				api('getAppDownload', {}, r => {
 					console.log(r)
 					this.downloadUrls = r.data.data;
+					// 保存安卓包名
+					if (r.data.data.androidPackageName) {
+						this.androidPackageName = r.data.data.androidPackageName;
+					}
 					this.$refs.downloadPopup.open();
 				});
 			},
@@ -390,22 +395,22 @@
 			// 下载iOS版本
 			downloadIOS() {
 				// 先尝试打开已安装的应用
-				this.tryOpenInstalledApp();
+				this.tryOpenInstalledApp('cityexpressuser');
 				this.closeDownloadPopup();
 			},
 
 			// 下载Android版本
 			downloadAndroid() {
 				// 先尝试打开已安装的应用
-				this.tryOpenInstalledApp();
+				this.tryOpenInstalledApp('deliveryking');
 				this.closeDownloadPopup();
 			},
 
 			// 尝试打开已安装的应用
-			tryOpenInstalledApp() {
+			tryOpenInstalledApp(schema) {
 				const that = this;
 
-				const appSchema = 'cityexpressuser://pages/shanpinxungou/shangjia/shangjiaView?id=' + this.id +
+				const appSchema = schema + '://pages/shanpinxungou/shangjia/shangjiaView?id=' + this.id +
 					'&isShangjia=' + this.isShangjia;
 
 				// 在App环境中使用plus.runtime.openURL
@@ -603,12 +608,17 @@
 				api('getAppDownload', {}, r => {
 					console.log(r);
 
+					// 保存安卓包名
+					if (r.data.data.androidPackageName) {
+						this.androidPackageName = r.data.data.androidPackageName;
+					}
+
 					// 检测是否为安卓设备
 					const isAndroid = this.isAndroidDevice();
 
 					if (isAndroid) {
-						// 安卓设备下载APK
-						that.downloadAndroidAPK(r.data.data.androidUrl);
+						// 安卓设备跳转到谷歌商店
+						that.openGooglePlay('com.deliveryking.user');
 					} else {
 						// iOS设备打开App Store
 						that.openAppStore(r.data.data.iosUrl);
@@ -616,7 +626,55 @@
 				});
 			},
 
-			// 下载安卓APK
+			// 打开谷歌商店
+			openGooglePlay(packageName) {
+				const that = this;
+				uni.hideLoading();
+
+				if (!packageName) {
+					// 如果没有包名,提示错误
+					uni.showToast({
+						title: 'Package name not found',
+						icon: 'none',
+						duration: 2000
+					});
+					return;
+				}
+
+				// 构建谷歌商店URL
+				const googlePlayUrl = `https://play.google.com/store/apps/details?id=${packageName}`;
+
+				// 在H5环境中
+				// #ifdef H5
+				// 直接跳转到谷歌商店
+				window.location.href = googlePlayUrl;
+				// #endif
+
+				// 在App环境中
+				// #ifdef APP-PLUS
+				plus.runtime.openURL(googlePlayUrl, function(res) {
+					console.log('Opening Google Play Store success');
+				}, function(err) {
+					console.log('Opening Google Play Store failed');
+					// 如果打开失败,提供手动下载选项
+					uni.showModal({
+						title: that.$t('download.download_failed'),
+						content: that.$t('download.download_failed_manual'),
+						showCancel: true,
+						cancelText: that.$t('comp.quxiao'),
+						confirmText: that.$t('comp.queren'),
+						success: function(res) {
+							if (res.confirm) {
+								// 使用浏览器打开谷歌商店链接
+								plus.runtime.openURL(googlePlayUrl);
+							}
+						}
+					});
+				});
+				// #endif
+			},
+
+			// 下载安卓APK(备用方法)
 			downloadAndroidAPK(androidUrl) {
 				const that = this;
 

+ 23 - 11
uniCloud-aliyun/cloudfunctions/uni-push/index.js

@@ -1,14 +1,26 @@
 // 简单的使用示例  
-'use strict';  
-const uniPush = uniCloud.getPushManager({appId:"__UNI__BC78306"}) //注意这里需要传入你的应用appId  
-exports.main = async (event, context) => {  
+'use strict';
+const uniPush = uniCloud.getPushManager({
+	appId: "__UNI__BC78306"
+}) //注意这里需要传入你的应用appId  
+exports.main = async (event, context) => {
+	let ps;
+	if (event.httpMethod === 'POST' && event.body) {
+		ps = JSON.parse(event.body); // POST: 从 body 解析 JSON
+	} else {
+		ps = event.queryStringParameters || {}; // GET: 从 query 取
+	}
+
+	// 后续逻辑不变,ps 里都有 cid、title、content、payload
+	var cids = (ps.cid || '').split(',').map(c => c.trim()).filter(c => c);
 	console.log(event);
 	var ps = event.queryStringParameters;
-    return await uniPush.sendMessage({  
-        "push_clientid": ps.cid,     //填写上一步在uni-app客户端获取到的客户端推送标识push_clientid  
-        "force_notification":false,  //填写true,客户端就会对在线消息自动创建“通知栏消息”。  
-        "title": ps.title,      
-        "content": ps.content,  
-		"payload":ps.payload,
-    })  
-};
+	return await uniPush.sendMessage({
+		"push_clientid": cids.length === 1 ? cids[0] :
+		cids, // 单个用字符串,多个用数组 //填写上一步在uni-app客户端获取到的客户端推送标识push_clientid  
+		"force_notification": false, //填写true,客户端就会对在线消息自动创建“通知栏消息”。  
+		"title": ps.title,
+		"content": ps.content,
+		"payload": ps.payload,
+	})
+};