Commit 99922a000698b7ad3b37ee2b6bd92798ccca6d22

Authored by 王强
1 parent 2e4d7ae3

购好物,升级OpenInstall

src/components/callAppBox/callAppBox.vue
@@ -55,6 +55,13 @@ export default { @@ -55,6 +55,13 @@ export default {
55 // 拼接参数字符串,根据分享参数拼接 55 // 拼接参数字符串,根据分享参数拼接
56 let shareString = "shop_shop_type=" + this.callApps.funcs.callAppParams.shop_shop_type + "&shop_to=" + this.callApps.funcs.callAppParams.shop_to + "&shop_type=" + this.callApps.funcs.callAppParams.shop_type + "&share_mold=" + this.callApps.funcs.callAppParams.share_mold; 56 let shareString = "shop_shop_type=" + this.callApps.funcs.callAppParams.shop_shop_type + "&shop_to=" + this.callApps.funcs.callAppParams.shop_to + "&shop_type=" + this.callApps.funcs.callAppParams.shop_type + "&share_mold=" + this.callApps.funcs.callAppParams.share_mold;
57 57
  58 + // 判断是否有扩展参数,如果有,拼接扩展参数到原始字符串
  59 + if (this.callApps.funcs.callAppParams.shop_ext) {
  60 +
  61 + // 拼接扩展参数到原始字符串
  62 + shareString += "&shop_extra=" + this.callApps.funcs.callAppParams.shop_ext;
  63 + }
  64 +
58 // Base64位编码加密 65 // Base64位编码加密
59 const CryptoJS = require("crypto-js"); 66 const CryptoJS = require("crypto-js");
60 const wordArray = CryptoJS.enc.Utf8.parse(shareString); 67 const wordArray = CryptoJS.enc.Utf8.parse(shareString);
src/pages/common/common.vue
@@ -690,11 +690,31 @@ @@ -690,11 +690,31 @@
690 shop_shop_type: datas.inside_aes.shop_type 690 shop_shop_type: datas.inside_aes.shop_type
691 }); 691 });
692 692
  693 + // 判断是否有扩展参数,如果有,传递扩展参数
  694 + if (datas.inside_aes.ext) {
  695 +
  696 + // 添加扩展参数
  697 + Object.assign(this.schemeParams, {
  698 + shop_ext: datas.inside_aes.ext
  699 + });
  700 + }
  701 +
693 // 遍历对象,重新编码 702 // 遍历对象,重新编码
694 for (let index in this.schemeParams) { 703 for (let index in this.schemeParams) {
695 this.schemeParams[index] = encodeURIComponent(decodeURIComponent(this.schemeParams[index])); 704 this.schemeParams[index] = encodeURIComponent(decodeURIComponent(this.schemeParams[index]));
696 } 705 }
697 706
  707 + // 如果在iOS内,重新设置OpenInstall参数
  708 + if (this.isiPhone.value) {
  709 +
  710 + // 判断openInstallReady函数是否存在
  711 + if (typeof openInstallReady === 'function') {
  712 +
  713 + // 重新设置OpenInstall参数
  714 + openInstallReady(this.schemeParams);
  715 + }
  716 + }
  717 +
698 // 设置唤起App对象 718 // 设置唤起App对象
699 this.$set(this, "callApps", { 719 this.$set(this, "callApps", {
700 funcs: { 720 funcs: {
static/js/cnLive_openinstall.js
@@ -112,61 +112,77 @@ if (url.toLowerCase() === "managemall.cnlive.com" || url.toLowerCase() === "mana @@ -112,61 +112,77 @@ if (url.toLowerCase() === "managemall.cnlive.com" || url.toLowerCase() === "mana
112 } else { 112 } else {
113 appKey = "gzqtwt"; //测试appKey 113 appKey = "gzqtwt"; //测试appKey
114 } 114 }
115 -//初始化openInstall方法  
116 -function openInstallReady() {  
117 - var timestamp = Date.parse(new Date());  
118 - openInstallData = parseQueryString();  
119 - openInstallData.channelCodeName = channelCodeName;  
120 - openInstallData.timestamp = timestamp;  
121 - openInstallData.changeSecDefChannel = true; //安卓默认定位二级频道  
122 - openInstallData.type = type;  
123 - // 处理礼物通过openinstall唤起APP  
124 - let share_mold = encodeURIComponent(decodeURIComponent(openInstallData.share_mold));  
125 - let shop_type = encodeURIComponent(decodeURIComponent(openInstallData.shop_type));  
126 - let shop_to = encodeURIComponent(decodeURIComponent(openInstallData.shop_to));  
127 - let shop_shop_type = encodeURIComponent(decodeURIComponent(openInstallData.shop_shop_type));  
128 - // 把值链接的方式绑定到shopShoptype  
129 - let shopCollection =  
130 - "shop_shop_type=" +  
131 - shop_shop_type +  
132 - "&shop_to=" +  
133 - shop_to +  
134 - "&shop_type=" +  
135 - shop_type +  
136 - "&share_mold=" +  
137 - share_mold;  
138 - // Base64位编码加密  
139 - // var CryptoJS = require('crypto-js')  
140 - var wordArray = CryptoJS.enc.Utf8.parse(shopCollection);  
141 - let shopData = encodeURIComponent(CryptoJS.enc.Base64.stringify(wordArray));  
142 - openInstallData.shopData = shopData;  
143 - mm = new OpenInstall(  
144 - {  
145 - /*appKey必选参数,openinstall平台为每个应用分配的ID*/  
146 - appKey: appKey,  
147 - /*可选参数,自定义android平台的apk下载文件名;个别andriod浏览器下载时,中文文件名显示乱码,请慎用中文文件名!*/  
148 - //apkFileName : 'com.fm.openinstalldemo-v2.2.0.apk',  
149 - /*可选参数,是否优先考虑拉起app,以牺牲下载体验为代价*/  
150 - //preferWakeup:true,  
151 - /*自定义遮罩的html*/  
152 - //mask:function(){  
153 - // return "<div id='openinstall_shadow' style='position:fixed;left:0;top:0;background:rgba(0,255,0,0.5);filter:alpha(opacity=50);width:100%;height:100%;z-index:10000;'></div>"  
154 - //},  
155 - /*openinstall初始化完成的回调函数,可选*/  
156 - channelCode: channelName,  
157 - onready: function() {  
158 - /*在app已安装的情况尝试拉起app*/  
159 - /*不管是iOS还是安卓必须在openInstall后台打开启用scheme按钮才能执行schemeWakeup方法*/  
160 - /*在ios9.2以下schemeWakeup方法才能在openInstall初始化完毕之后执行拉起app操作,  
161 - ios9.2以上必须通过点击触发wakeupOrInstall方法才能拉起app */  
162 - /*在安卓里只要打开了启用scheme按钮,schemeWakeup方法就会执行*/  
163 - /*隐藏以下代码是为了解决安卓网家家app内部打开h5会弹出跳转外部应用的bug*/  
164 - //var m = this;  
165 - //m.schemeWakeup();  
166 - }  
167 - },  
168 - openInstallData  
169 - ); 115 +/**
  116 + * 初始化openInstall方法
  117 + * @param {Object} schemeParams [从接口取到的schemeParams参数,对象形式的,未做任何处理]
  118 + */
  119 +function openInstallReady(schemeParams) {
  120 +
  121 + // 初始化数据
  122 + var timestamp = Date.parse(new Date());
  123 + openInstallData = parseQueryString();
  124 + openInstallData.channelCodeName = channelCodeName;
  125 + openInstallData.timestamp = timestamp;
  126 + openInstallData.changeSecDefChannel = true; //安卓默认定位二级频道
  127 + openInstallData.type = type;
  128 +
  129 + // 初始化通过openinstall唤起APP参数
  130 + let share_mold, shop_type, shop_to, shop_shop_type, shop_ext;
  131 +
  132 + // 判断如果传入了schemeParams的话,就不执行从地址栏取参数的操作,重新初始化一次OpenInstall
  133 + if (schemeParams && typeof schemeParams === 'object' && schemeParams.share_mold && schemeParams.shop_type && schemeParams.shop_to && schemeParams.shop_shop_type) {
  134 +
  135 + // 处理通过openinstall唤起APP参数
  136 + share_mold = schemeParams.share_mold;
  137 + shop_type = schemeParams.shop_type;
  138 + shop_to = schemeParams.shop_to;
  139 + shop_shop_type = schemeParams.shop_shop_type;
  140 + shop_ext = (schemeParams.shop_ext ? schemeParams.shop_ext : '');
  141 + } else {
  142 +
  143 + // 处理通过openinstall唤起APP参数
  144 + share_mold = encodeURIComponent(decodeURIComponent(openInstallData.share_mold));
  145 + shop_type = encodeURIComponent(decodeURIComponent(openInstallData.shop_type));
  146 + shop_to = encodeURIComponent(decodeURIComponent(openInstallData.shop_to));
  147 + shop_shop_type = encodeURIComponent(decodeURIComponent(openInstallData.shop_shop_type));
  148 + shop_ext = encodeURIComponent(decodeURIComponent(openInstallData.shop_ext));
  149 + }
  150 +
  151 + // 把值链接的方式绑定到shopShoptype
  152 + let shareString = "shop_shop_type=" + shop_shop_type + "&shop_to=" + shop_to + "&shop_type=" + shop_type + "&share_mold=" + share_mold + (shop_ext ? '&shop_extra=' + shop_ext : '');
  153 +
  154 + // Base64位编码加密
  155 + // var CryptoJS = require('crypto-js')
  156 + var wordArray = CryptoJS.enc.Utf8.parse(shareString);
  157 + let shopData = encodeURIComponent(CryptoJS.enc.Base64.stringify(wordArray));
  158 +
  159 + // 设置OpenInstall自定义参数
  160 + openInstallData.shopData = shopData;
  161 +
  162 + mm = new OpenInstall({
  163 + /*appKey必选参数,openinstall平台为每个应用分配的ID*/
  164 + appKey: appKey,
  165 + /*可选参数,自定义android平台的apk下载文件名;个别andriod浏览器下载时,中文文件名显示乱码,请慎用中文文件名!*/
  166 + //apkFileName : 'com.fm.openinstalldemo-v2.2.0.apk',
  167 + /*可选参数,是否优先考虑拉起app,以牺牲下载体验为代价*/
  168 + //preferWakeup:true,
  169 + /*自定义遮罩的html*/
  170 + //mask:function(){
  171 + // return "<div id='openinstall_shadow' style='position:fixed;left:0;top:0;background:rgba(0,255,0,0.5);filter:alpha(opacity=50);width:100%;height:100%;z-index:10000;'></div>"
  172 + //},
  173 + /*openinstall初始化完成的回调函数,可选*/
  174 + channelCode: channelName,
  175 + onready: function() {
  176 + /*在app已安装的情况尝试拉起app*/
  177 + /*不管是iOS还是安卓必须在openInstall后台打开启用scheme按钮才能执行schemeWakeup方法*/
  178 + /*在ios9.2以下schemeWakeup方法才能在openInstall初始化完毕之后执行拉起app操作,
  179 + ios9.2以上必须通过点击触发wakeupOrInstall方法才能拉起app */
  180 + /*在安卓里只要打开了启用scheme按钮,schemeWakeup方法就会执行*/
  181 + /*隐藏以下代码是为了解决安卓网家家app内部打开h5会弹出跳转外部应用的bug*/
  182 + //var m = this;
  183 + //m.schemeWakeup();
  184 + },
  185 + }, openInstallData);
170 } 186 }
171 187
172 // $.ajax({ 188 // $.ajax({
@@ -198,4 +214,4 @@ function openInstallReady() { @@ -198,4 +214,4 @@ function openInstallReady() {
198 // } 214 // }
199 // }); 215 // });
200 // 本地测试 216 // 本地测试
201 -openInstallReady(); 217 -openInstallReady();
  218 +openInstallReady();
202 \ No newline at end of file 219 \ No newline at end of file