|
@@ -4,31 +4,26 @@ import md5 from './md5'
|
|
|
let _interval = 30000
|
|
|
let _yyuid = 0
|
|
|
let gh_id = ''
|
|
|
-let loginData = ''
|
|
|
-let appid = ''
|
|
|
-
|
|
|
+let key = 'KeB357eb6b9G719R'
|
|
|
|
|
|
let M = {
|
|
|
launchOptions: function (name) {
|
|
|
let param = wx.getLaunchOptionsSync()
|
|
|
-
|
|
|
- _yyuid = param['query']['_yyuid'] ? param['query']['_yyuid'] : ''
|
|
|
- // let _md5 = param['query']['_md5']
|
|
|
- //gh_id格式:`gh${跳转的appid}_${昵称}_${自定义appid}`
|
|
|
+ let verifyMd5 = M.getSign(param.query,key)
|
|
|
|
|
|
+ // let _md5 = param['query']['_md5']
|
|
|
+ _yyuid = param['query']['_yyuid']
|
|
|
if(param['query']['scene']) {
|
|
|
gh_id = param['query']['scene'].startsWith('gh') ? param['query']['scene'] : ''
|
|
|
- appid = gh_id ? gh_id.split('_')[2] : ''
|
|
|
}
|
|
|
- console.log(gh_id)
|
|
|
- console.log(appid)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
param['query'] = JSON.stringify(param['query'])
|
|
|
param['referrerInfo'] = JSON.stringify(param['referrerInfo'])
|
|
|
param['name'] = name
|
|
|
-
|
|
|
|
|
|
- let url = `${lib.host}sdk/launchOptions`
|
|
|
+ let url = `${lib.host}sdk/launchOptions?verify=${verifyMd5}`
|
|
|
lib.post(url, param, function (objResult) {
|
|
|
if (objResult.result) {
|
|
|
console.debug(url + ':' + objResult.msg);
|
|
@@ -37,14 +32,14 @@ let M = {
|
|
|
console.error(objResult.msg);
|
|
|
}
|
|
|
});
|
|
|
- },
|
|
|
+ },
|
|
|
gameAction: function (name, action) {
|
|
|
if (!_yyuid) {
|
|
|
console.debug('没有yyuid,无需上报');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- let param = { name, _yyuid, gh_id }
|
|
|
+ let param = { name, _yyuid, gh_id }
|
|
|
|
|
|
let url = `${lib.host}sdk/${action}`
|
|
|
param['_sign'] = M.getSign(param)
|
|
@@ -57,22 +52,21 @@ let M = {
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- getSign(param) {
|
|
|
+ getSign(param,key) {
|
|
|
let str = ''
|
|
|
for (let key in param) {
|
|
|
str += `&${key}=${param[key]}`
|
|
|
}
|
|
|
str = str.substr(1);
|
|
|
+ str = str ? str : new Date().getTime()
|
|
|
str = encodeURI(str)
|
|
|
|
|
|
- let sign = md5.hexMD5(str)
|
|
|
+ let sign = key ? md5.hexMD5(key + str) : md5.hexMD5(str)
|
|
|
// console.log(`str:${str}, sign:${sign}`)
|
|
|
|
|
|
return sign
|
|
|
},
|
|
|
- reportDw() {
|
|
|
-
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
export default class GameLife {
|
|
@@ -84,31 +78,8 @@ export default class GameLife {
|
|
|
initEvent() {
|
|
|
let self = this
|
|
|
if (lib.wx) {
|
|
|
- let loginCache = wx.getStorageSync('loginData')
|
|
|
- M.launchOptions(self.name);
|
|
|
- if(_yyuid) {
|
|
|
- _invoked()
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if(loginCache) {
|
|
|
- _yyuid = loginCache
|
|
|
- _invoked()
|
|
|
- } else {
|
|
|
- if(!appid) return
|
|
|
- // 已经授权,可以直接调用 getUserInfo 获取头像昵称
|
|
|
- _getLoginCode()
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取yyuid后的回调
|
|
|
- */
|
|
|
- function _invoked() {
|
|
|
// 上报启动参数
|
|
|
-
|
|
|
+ M.launchOptions(self.name);
|
|
|
|
|
|
// 防止重复绑定,先解绑
|
|
|
wx.offShow(_show)
|
|
@@ -116,49 +87,10 @@ export default class GameLife {
|
|
|
// 绑定事件
|
|
|
wx.onShow(_show)
|
|
|
wx.onHide(_hide)
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 获取登录js_code
|
|
|
- */
|
|
|
-
|
|
|
- function _getLoginCode() {
|
|
|
- wx.login({
|
|
|
- success(res) {
|
|
|
- let postData = {
|
|
|
- appid,
|
|
|
- js_code: res.code,
|
|
|
- simple: 1
|
|
|
- }
|
|
|
- _getLoginData(postData)
|
|
|
- },
|
|
|
- fail(){
|
|
|
- console.log('获取js_code失败')
|
|
|
- }
|
|
|
- })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 请求接口获取登录信息
|
|
|
- */
|
|
|
- function _getLoginData(postData) {
|
|
|
- let url = 'https://wxserver.duowan.com/auth/wxaGetUserInfo'
|
|
|
- lib.get(url,postData,(ret) => {
|
|
|
- loginData = ret.data.openid
|
|
|
- console.log('```````````````setStorage```````````````')
|
|
|
- console.log(loginData)
|
|
|
- wx.setStorage({
|
|
|
- key: 'loginData',
|
|
|
- data: loginData
|
|
|
- })
|
|
|
-
|
|
|
- _yyuid = loginData
|
|
|
- _invoked()
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
* 开始小游戏心跳响应
|
|
|
*/
|
|
|
function _startEcho() {
|