Authored by huangyi

活动sdk init

... ... @@ -2,17 +2,18 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover">
<meta http-equiv="X-UA-Compatible" content="chrome=1,IE=edge">
<title>Title</title>
</head>
<body>
<div class="auth">1111111</div>
<a class="auth" href="http://www.baidu.com">123123</a>
<a class="auth" href="http://www.baidu.com">123123</a>
<div id="aaa">232323</div>
<script src="../build/sdk.js"></script>
<script>
document.getElementById('aaa').onclick = function(event){
_jssdk.goLogin();
document.getElementById('aaa').onclick = function (event) {
yo_sdk.goLogin();
}
</script>
</body>
... ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover">
<meta http-equiv="X-UA-Compatible" content="chrome=1,IE=edge">
<title>Title</title>
</head>
<body>
<div id="share"> 分享</div>
<script src="../build/sdk.js"></script>
<script>
let shareData = {
title: '国潮崛起年,中西碰撞博出位!',
imgUrl: 'https://img01.yohoboys.com/o_1cnilugbs15ajak1gfo1d2h1p348.png?imageView2/1/w/200/h/200',
desc: '这里有一份中西潮流榜单,请收好!',
link: location.href,
success: function () {
alert('1123')
}
};
// let sign = window.yo_sdk.wxSignature;
// sign().then(function(r){
// console.log(r)
// window.yo_sdk.wxShare(shareData)
// })
window.yo_sdk.wxSignature(window.yo_sdk.wxShare(shareData));
</script>
</body>
</html>
\ No newline at end of file
... ...
import base from './public/base'
import Login from './public/login'
import Goto from './public/goto'
import share from './public/share'
import wxCtrl from './public/share'
const env = base.env();
const loginUrl = base.loginUrl();
const uid = base.uid();
const login = new Login({loginUrl, env, uid});
const goto = new Goto(env);
const wxShare = new share();
export default {
goLogin: login.goLogin,
isLogin: base.uid,
uid: base.geAppUid,
env: env,
link: goto.link,
goBack: goto.goBack,
wxShare: wxShare.wxShare
wxShare: wxCtrl.wxShare,
wxSignature: wxCtrl.wxSignature
}
... ...
... ... @@ -23,7 +23,7 @@ const parseUrl = (url) => {
query: query
};
}
let env = ''
export default {
//evn
env: function () {
... ... @@ -31,21 +31,21 @@ export default {
if (!envFlag && navigator.userAgent.match(/yohobuy/i)) {
document.addEventListener('deviceready', function () {
});
return 'app';
env = 'app';
} else if ((!envFlag && navigator.userAgent.match(/miniProgram/i)) || (envFlag == 'miniprogram')) {
return 'miniprogram';
env = 'miniprogram';
} else if (location.origin === 'https://www.yohobuy.com') {
return 'pc'
env = 'pc'
}else{
return 'h5'
env = 'h5'
}
return env
},
//url
loginUrl: function () {
let _env = this.env();
let url, refer = location.href.split('?')[0];
url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer);
if (_env === 'app') {
if (env === 'app') {
refer = parseUrl(refer);
if (/Android/i.test(navigator.userAgent || '')) {
if (url.indexOf('?') < 0) {
... ... @@ -72,20 +72,20 @@ export default {
needlogout: 'Y'
}
});
}else if(_env === 'pc'){
}else if(env === 'pc'){
url = 'https://www.yoho/signin.html?refer=' + encodeURIComponent(location.href) + '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + refer.replace(/\//g, '\\/') + '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
}
return url;
},
//uid
uid: async function () {
let _env = this.env();
let result = await jsonp('https://m.yohobuy.com/passport/login/user');
if (result.code === 200)
return result.data;
else if (_env === 'app' || _env === 'miniprogram')
return cookies.cookie('app_uid') || getQueryObj().uid || 0;
else if (env === 'app' || env === 'miniprogram')
return Number(cookies.cookie('app_uid')) || Number(getQueryObj().uid) || 0;
else
return 0;
}
},
geAppUid: Number(cookies.cookie('app_uid')) || Number(getQueryObj().uid) || 0
}
... ...
import wx from 'weixin-js-sdk';
import {linkToMiniApp,invokeMethod} from "../utils/common";
let env ;
export default class {
constructor(env) {
this.env = env;
constructor(_env) {
env = _env;
this.createButton();
}
createButton() {
if (!document.getElementById('yosdk-goto') && this.env !== 'miniprogram') {
if (!document.getElementById('yosdk-goto') && env !== 'miniprogram') {
let a = document.createElement('a')
a.style.position = 'fixed';
a.style.top = 0;
... ... @@ -31,7 +32,7 @@ export default class {
let url = element.getAttribute('data-url') || '';
let name = element.getAttribute('data-name') || '';
let linkUrl = '';
if (this.env === 'miniprogram') {
if (env === 'miniprogram') {
if (type === 'product') {
linkUrl = '/pages/goodsDetail/goodsDetail?productSkn=' + id + '&page_name=goodsList&page_param=5'
} else if (type === 'brand') {
... ... @@ -40,7 +41,7 @@ export default class {
linkUrl = url.split('?')[0];
}
return linkToMiniApp(linkUrl, type);
} else if (this.env === 'pc'){
} else if (env === 'pc'){
if (type === 'product') {
linkUrl = 'https://www.yohobuy.com/product/'+id+'.html'
} else if (type === 'brand') {
... ... @@ -64,9 +65,9 @@ export default class {
goBack () {
if(this.env === 'app'){
if(env === 'app'){
invokeMethod({method:'go.back'})
}else if(this.env === 'miniprogram'){
}else if(env === 'miniprogram'){
wx.miniProgram.navigateBack();
}else{
history.go(-1);
... ...
import wx from 'weixin-js-sdk';
let env, url, uri;
export default class {
constructor(obj) {
this.env = obj.env;
this.url = obj.loginUrl;
obj.uid.then(uid=>{
this.uid = uid;
env = obj.env
url = obj.loginUrl;
uri = ''
obj.uid.then(uid => {
this.uri = uid
this.createloginButton(uid);
this.auth(uid);
});
}
createloginButton(uid) {
if (!document.getElementById('yosdk-login') && ! uid && this.env !== 'miniprogram') {
if (!document.getElementById('yosdk-login') && !uid && env !== 'miniprogram') {
let a = document.createElement('a')
a.style.position = 'fixed';
a.style.top = 0;
... ... @@ -23,7 +25,7 @@ export default class {
a.style.background = 'transparent';
a.style.color = 'transparent';
a.setAttribute('id', 'yosdk-login');
a.setAttribute('href', this.url);
a.setAttribute('href', url);
document.body.appendChild(a);
}
}
... ... @@ -35,16 +37,21 @@ export default class {
list.forEach((value) => {
value.onclick = function (event) {
event.preventDefault();
let loginButton = document.getElementById('yosdk-login');
loginButton.click();
if (env === 'miniprogram') {
wx.miniProgram.switchTab({url: '/pages/userCenter/userCenter'});
} else {
let loginButton = document.getElementById('yosdk-login');
loginButton.click();
}
}
})
return true;
}
}
}
goLogin() {
if (this.env === 'miniprogram') {
if (env === 'miniprogram') {
return wx.miniProgram.switchTab({url: '/pages/userCenter/userCenter'});
} else {
let loginButton = document.getElementById('yosdk-login');
... ...
... ... @@ -3,65 +3,72 @@ import httpServer from '../utils/jsonp';
import wx from "weixin-js-sdk";
const _weChatInterface = '//action.yoho.cn/api/share/getSignPackage';//签名等相关配置,yoho公众号
export default class {
constructor() {
this.wxSignature();
}
export default {
wxSignature() {
wxSignature: fun => {
httpServer(_weChatInterface + "?pageurl=" + encodeURIComponent(location.href.split('#')[0])).then((json) => {
let _appId = json.appId.toString();
let _timestamp = json.timestamp;
let _nonceStr = json.nonceStr.toString();
let _signature = json.signature.toString();
wx.config({
debug: false,
appId: _appId,
timestamp: _timestamp,
nonceStr: _nonceStr,
signature: _signature,
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'hideMenuItems',
'showMenuItems',
'hideAllNonBaseMenuItem',
'showAllNonBaseMenuItem',
'translateVoice',
'startRecord',
'stopRecord',
'onVoiceRecordEnd',
'playVoice',
'pauseVoice',
'stopVoice',
'uploadVoice',
'onVoicePlayEnd',
'downloadVoice',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
'getNetworkType',
'openLocation',
'getLocation',
'hideOptionMenu',
'showOptionMenu',
'closeWindow',
'scanQRCode',
'chooseWXPay',
'openProductSpecificView',
'addCard',
'chooseCard',
'openCard'
]
});
if (!json.appId) {
document.getElementById('share').innerText = 'false';
return false;
} else {
document.getElementById('share').innerText = 'true';
let _appId = json.appId.toString();
let _timestamp = json.timestamp;
let _nonceStr = json.nonceStr.toString();
let _signature = json.signature.toString();
wx.config({
debug: false,
appId: _appId,
timestamp: _timestamp,
nonceStr: _nonceStr,
signature: _signature,
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'hideMenuItems',
'showMenuItems',
'hideAllNonBaseMenuItem',
'showAllNonBaseMenuItem',
'translateVoice',
'startRecord',
'stopRecord',
'onVoiceRecordEnd',
'playVoice',
'pauseVoice',
'stopVoice',
'uploadVoice',
'onVoicePlayEnd',
'downloadVoice',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
'getNetworkType',
'openLocation',
'getLocation',
'hideOptionMenu',
'showOptionMenu',
'closeWindow',
'scanQRCode',
'chooseWXPay',
'openProductSpecificView',
'addCard',
'chooseCard',
'openCard'
]
});
fun && setTimeout(fun,500);
return true;
}
})
}
},
wxShare: shareDate => {
document.getElementById('share').innerText = 'wxShare';
wxShare(shareDate) {
let share_data = shareDate || {
title: '',
imgUrl: '',
... ... @@ -71,20 +78,15 @@ export default class {
}
};
wx.ready(function () {
//构造分享信息
let shareData = share_data;
let voice_localId = '';
let is_start = false;
document.getElementById('share').innerText = JSON.stringify(share_data);
// 2.1 “分享给朋友”
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareAppMessage(share_data);
// 2.2 “分享到朋友圈”
wx.onMenuShareTimeline(shareData);
wx.onMenuShareTimeline(share_data);
// 2.3 “分享到QQ”
wx.onMenuShareQQ(shareData);
wx.onMenuShareQQ(share_data);
// 2.4 “分享到微博”
wx.onMenuShareWeibo(shareData);
//document.getElementById('media').play();
//bindUploadEvent();
wx.onMenuShareWeibo(share_data);
});
}
}
... ...
... ... @@ -3,7 +3,9 @@ import wx from "weixin-js-sdk";
const invokeMethod = (obj) => {
let appInterface = window.yohoInterface;
if (appInterface) {
appInterface.triggerEvent(obj.success || function(){}, obj.fail || function(){}, {
appInterface.triggerEvent(obj.success || function () {
}, obj.fail || function () {
}, {
method: obj.method,
arguments: obj.args
});
... ... @@ -12,28 +14,24 @@ const invokeMethod = (obj) => {
}
}
const linkToMiniApp = (goUrl,type) => {
const linkToMiniApp = (goUrl, type) => {
let url = goUrl || '';
if (url && url.indexOf('http') < 0 && type === 'other') {
url = document.location.protocol + '//' + document.location.host + url;
}
if (url) {
let base_url = decodeURIComponent(url).split('?')[0];
let params = getQueryObj(url);
let paramStr = '';
Object.keys(params).forEach(key => {
paramStr += paramStr === '' ? '?' + key + '=' + params[key] : '&' + key + '=' + params[key];
})
let mini_url = '/pages/webview/webview?url=' + base_url;
let scene = mini_url + encodeURIComponent(paramStr);
let scene;
if (type === 'product' || type === 'brand') {
mini_url = url;
scene = mini_url;
scene = url;
} else {
let base_url = decodeURIComponent(url).split('?')[0];
let params = getQueryObj(url);
let paramStr = '';
Object.keys(params).forEach(key => {
paramStr += paramStr === '' ? '?' + key + '=' + params[key] : '&' + key + '=' + params[key];
})
scene = '/pages/webview/webview?url=' + base_url + encodeURIComponent(paramStr);
}
wx.miniProgram.navigateTo({url: scene});
return false;
} else {
... ... @@ -44,11 +42,9 @@ const linkToMiniApp = (goUrl,type) => {
const getQueryObj = (link) => {
let loc = decodeURIComponent(document.location.href);
if (link) {
loc = decodeURIComponent(link);
}
console.log('loc:', loc);
let variables = '';
let variableArr = [];
let finalArr = [];
... ...
... ... @@ -19,7 +19,7 @@ module.exports = {
path: path.resolve(__dirname, 'build'),
filename: 'sdk.js',
libraryTarget: 'umd',
library: "_jssdk",
library: "yo_sdk",
libraryExport: "default"
},
//插件
... ... @@ -41,7 +41,7 @@ module.exports = {
}
]
},
devtool: "source-map",
devtool: "inline-source-map",
//模块路径
resolve:{
alias: {
... ...