Compare commits

...

4 Commits
master ... io

12 changed files with 680 additions and 505 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "gamemall", "name": "gamemall",
"version": "0.0.2", "version": "1.0.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "gamemall", "name": "gamemall",
"version": "0.0.2", "version": "1.0.0",
"description": "游戏电商小程序", "description": "游戏电商小程序",
"main": "dist/app.js", "main": "dist/app.js",
"scripts": { "scripts": {

View File

@ -1,7 +1,7 @@
{ {
"description": "游戏电商小程序", "description": "游戏电商小程序",
"setting": { "setting": {
"urlCheck": false, "urlCheck": true,
"es6": false, "es6": false,
"postcss": false, "postcss": false,
"minified": false, "minified": false,
@ -10,7 +10,7 @@
"checkInvalidKey": true "checkInvalidKey": true
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"appid": "wx815bf59d472c0a63", "appid": "wx7d6509053659d9ed",
"projectname": "gamemall", "projectname": "gamemall",
"miniprogramRoot": "dist/", "miniprogramRoot": "dist/",
"simulatorType": "wechat", "simulatorType": "wechat",
@ -32,7 +32,7 @@
"list": [] "list": []
}, },
"miniprogram": { "miniprogram": {
"current": 0, "current": 2,
"list": [ "list": [
{ {
"id": 0, "id": 0,
@ -47,6 +47,17 @@
"pathName": "pages/buyvip", "pathName": "pages/buyvip",
"query": "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjNmUxYjk3NDA5MGY5NTYxM2M3YjgxOSIsImFjY291bnRfaWQiOiI2MDAxXzgwMDNfb0pZYXA1WlZSV0RGRm9Qd09GcGllQmVNRkVocyIsInNlc3Npb25faWQiOiIxNTUwNzU0Njg5XzE1NTA3MTc1OTRfYjA5YTVmOWYxODM0NDFmOWUxMDk1MGJmOTUyZTRjMjFfNTcyOWRkOWYyMzQ5NzdlM2IwMGNjOGFjYWRjMjFiOTQiLCJpYXQiOjE1NTA3NTQ2ODl9.GkUGGb2vwTE1xgZ-UKwl6Tfs3NFawE2V3ZAH91_syY4", "query": "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjNmUxYjk3NDA5MGY5NTYxM2M3YjgxOSIsImFjY291bnRfaWQiOiI2MDAxXzgwMDNfb0pZYXA1WlZSV0RGRm9Qd09GcGllQmVNRkVocyIsInNlc3Npb25faWQiOiIxNTUwNzU0Njg5XzE1NTA3MTc1OTRfYjA5YTVmOWYxODM0NDFmOWUxMDk1MGJmOTUyZTRjMjFfNTcyOWRkOWYyMzQ5NzdlM2IwMGNjOGFjYWRjMjFiOTQiLCJpYXQiOjE1NTA3NTQ2ODl9.GkUGGb2vwTE1xgZ-UKwl6Tfs3NFawE2V3ZAH91_syY4",
"scene": null "scene": null
},
{
"id": 2,
"name": "io",
"pathName": "pages/io",
"query": "",
"scene": 1037,
"referrerInfo": {
"appId": "1231231",
"extraData": "{ \"data\": \"hello box\", \"isoffical\" : false }"
}
} }
] ]
} }

View File

@ -21,6 +21,8 @@
import wepy from 'wepy' import wepy from 'wepy'
import 'wepy-async-function' import 'wepy-async-function'
import jcEvent from './common/jc-event'; import jcEvent from './common/jc-event';
import global from './common/global';
var g = require('./common/global').default;
let sdkManage = require('./jcfw/SDKManage'); let sdkManage = require('./jcfw/SDKManage');
@ -30,6 +32,7 @@ export default class extends wepy.app {
'pages/index', 'pages/index',
'pages/product', 'pages/product',
'pages/buyvip', 'pages/buyvip',
'pages/io',
'pages/detail' 'pages/detail'
], ],
window: { window: {
@ -43,18 +46,16 @@ export default class extends wepy.app {
globalData = { globalData = {
userInfo: null, userInfo: null,
gameToken: null, gameToken: null,
dataType: 'game' dataType: 'game',
fromAppId: '',
extraData: {},
isPay: false,
} }
constructor () { constructor () {
super() super()
this.use('requestfix'); this.use('requestfix');
this.use('promisify'); this.use('promisify');
sdkManage.init();
sdkManage.Login(() => {
jcEvent.emit(jcEvent.events.NEED_UPDATE_CFG, {});
console.log('finish parse jcfw');
});
//全局拦截器 //全局拦截器
this.intercept('request', { this.intercept('request', {
config(p) { config(p) {
@ -89,10 +90,29 @@ export default class extends wepy.app {
onShow(options) { onShow(options) {
console.log('app.onShow'); console.log('app.onShow');
console.log(options); console.log(options);
if (options.scene === 1037) { let isoffical = g.env === 'product';
if (options.scene === 1037 || options.scene === 1038) {
let params = options.query; let params = options.query;
this.globalData.gameToken = params.token; this.globalData.gameToken = params.token;
this.globalData.dataType = params.dataType; this.globalData.dataType = params.dataType;
if (options.referrerInfo) {
let referrerInfo = options.referrerInfo;
this.globalData.fromAppId = referrerInfo.appId;
this.globalData.extraData = referrerInfo.extraData;
isoffical = referrerInfo.extraData.isoffical
}
this.globalData.isPay = true;
} else {
this.globalData.isPay = false;
}
sdkManage.isoffical = isoffical;
g.env = isoffical ? 'product' : 'test';
if (!(sdkManage.session_id && sdkManage.account_id)) {
sdkManage.init();
sdkManage.Login(() => {
jcEvent.emit(jcEvent.events.LOGIN_FINISHED, {});
console.log('finish parse jcfw');
});
} }
} }

View File

@ -8,5 +8,8 @@ export default {
'赛车', '动作游戏','策略战棋', '其他', '赛车', '动作游戏','策略战棋', '其他',
'益智游戏', '体育游戏', '冒险游戏', '模拟战略', '益智游戏', '体育游戏', '冒险游戏', '模拟战略',
'桌面游戏', '音乐游戏', '第一人称射击' '桌面游戏', '音乐游戏', '第一人称射击'
] ],
payUrl: function(isOffice) {
return isOffice ? 'https://gamepay.kingsome.cn/webapp/index.php?c=Pay&a=aggregatePay':'https://gamepay-test.kingsome.cn/webapp/index.php?c=Pay&a=aggregatePay';
}
} }

View File

@ -8,19 +8,19 @@ export default {
events[name] = [{self, cb}] events[name] = [{self, cb}]
} }
}, },
remove (name, self) { remove (name, target) {
let cbArr = events[name]; let cbArr = events[name];
if (Array.isArray(cbArr)) { if (Array.isArray(cbArr)) {
events[name] = cbArr.filter(({target, cb}) => { events[name] = cbArr.filter(({self, cb}) => {
return target !== self return self !== target
}) })
} }
}, },
emit (name, data) { emit (name, data) {
let cbArr = events[name]; let cbArr = events[name];
if (Array.isArray(cbArr)) { if (Array.isArray(cbArr)) {
cbArr.map(({target, cb}) => { cbArr.map(({self, cb}) => {
cb.call(target, data) cb.call(self, data)
}) })
} }
}, },

View File

@ -1,14 +1,14 @@
var jcfw = require('./jcfw'); var jcfw = require('./jcfw');
var jcgamelog = jcfw.gamelog;
var jcshare = jcfw.share; var jcshare = jcfw.share;
var g = require('../common/global').default; var g = require('../common/global').default;
var SDKManage = function() { var SDKManage = function() {
this.isoffical = g.env === 'product'; this.isoffical = g.env === 'product';
this.gameId = 8003; this.gameId = 9002;
this.hasLogin = false; this.hasLogin = false;
this.vision = '1.0.0'; this.vision = '1.0.0';
this.ChannelId = 6001; this.ChannelId = 6001;
this.gamelog = jcfw.gamelog;
this.init = function() { this.init = function() {
jcfw.init(this.ChannelId, this.gameId, this.isoffical); jcfw.init(this.ChannelId, this.gameId, this.isoffical);
}; };
@ -47,6 +47,7 @@ var SDKManage = function() {
console.log(res); console.log(res);
wx.setStorageSync('account', res); wx.setStorageSync('account', res);
self.account_id = res.account_id; self.account_id = res.account_id;
self.session_id = res.session_id;
self.doLogin(); self.doLogin();
}, },
(neterr, logicerr, errmsg) => { (neterr, logicerr, errmsg) => {
@ -67,7 +68,14 @@ var SDKManage = function() {
}; };
var cbf = function(res) { var cbf = function(res) {
console.log('getGameConfig fail'); console.log('getGameConfig fail');
self.getGameConfig(); if (!self.cfgTryCount) {
self.cfgTryCount = 1;
} else {
self.cfgTryCount += 1;
}
if (self.cfgTryCount < 10) {
self.getGameConfig();
}
}; };
jcfw.cloud.initConfig(cb, cbf); jcfw.cloud.initConfig(cb, cbf);
// jcfw.getConfig('',cb,cbf); // jcfw.getConfig('',cb,cbf);

View File

@ -1,481 +1,481 @@
var httpclient = require('../common/httpclient'); var httpclient = require('../common/httpclient');
var urlbuilder = require('../common/urlbuilder'); var urlbuilder = require('../common/urlbuilder');
module.exports = { module.exports = {
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
// onLoad () {}, // onLoad () {},
// start () {}, // start () {},
// update (dt) {}, // update (dt) {},
__getConfig(accountid, sessionid, channelid, gameid, actionname, successcb, failcb){ __getConfig(accountid, sessionid, channelid, gameid, actionname, successcb, failcb){
channelid=6001; channelid=6001;
this.urlbd.clear(); this.urlbd.clear();
this.urlbd.addKV('c', 'Config') this.urlbd.addKV('c', 'Config')
.addKV('a', actionname) .addKV('a', actionname)
.addKV('account_id', accountid) .addKV('account_id', accountid)
.addKV('session_id', sessionid) .addKV('session_id', sessionid)
.addKV('gameid', gameid) .addKV('gameid', gameid)
.addKV('channel', channelid) .addKV('channel', channelid)
; ;
httpclient.httpGet(this.urlbd.baseurl, function(restext){ httpclient.httpGet(this.urlbd.baseurl, function(restext){
var obj = httpclient.JSON_parse(restext); var obj = httpclient.JSON_parse(restext);
if(obj.errcode == 0){ if(obj.errcode == 0){
//console.log('[__getConfig]success!'+JSON.stringify(obj)); //console.log('[__getConfig]success!'+JSON.stringify(obj));
var kvobj = httpclient.JSON_parse(obj.KVList); var kvobj = httpclient.JSON_parse(obj.KVList);
if(kvobj){ if(kvobj){
successcb && successcb(kvobj); successcb && successcb(kvobj);
}else{ }else{
failcb && failcb(0, -1, "kvlist is not obj"); failcb && failcb(0, -1, "kvlist is not obj");
} }
}else{ }else{
//console.log('[__getConfig]failed!'+obj.errcode+":"+obj.errmsg); //console.log('[__getConfig]failed!'+obj.errcode+":"+obj.errmsg);
failcb && failcb(0, obj.errcode, obj.errmsg); failcb && failcb(0, obj.errcode, obj.errmsg);
} }
}, function(errcode, errmsg){ }, function(errcode, errmsg){
//console.log('[__getConfig]failed!'+errcode+":"+errmsg); //console.log('[__getConfig]failed!'+errcode+":"+errmsg);
failcb && failcb(errcode, 0, errmsg); failcb && failcb(errcode, 0, errmsg);
}); });
}, },
__getStorage(accountid, sessionid, token, skey, successcb, failcb){ __getStorage(accountid, sessionid, token, skey, successcb, failcb){
this.urlbd.clear(); this.urlbd.clear();
this.urlbd.addKV('c', 'CloudStorage') this.urlbd.addKV('c', 'CloudStorage')
.addKV('a', 'getStorage') .addKV('a', 'getStorage')
.addKV('account_id', accountid) .addKV('account_id', accountid)
.addKV('session_id', sessionid) .addKV('session_id', sessionid)
.addKV('access_token', token) .addKV('access_token', token)
.addKV('keys', skey); .addKV('keys', skey);
httpclient.httpGet(this.urlbd.baseurl, function(restext){ httpclient.httpGet(this.urlbd.baseurl, function(restext){
var obj = httpclient.JSON_parse(restext); var obj = httpclient.JSON_parse(restext);
if(obj.errcode == 0){ if(obj.errcode == 0){
//console.log('[__getStorage]success!'+JSON.stringify(obj)); //console.log('[__getStorage]success!'+JSON.stringify(obj));
//var kvobj = httpclient.JSON_parse(obj.KVList); //var kvobj = httpclient.JSON_parse(obj.KVList);
var kvobj = obj.KVList; var kvobj = obj.KVList;
if(kvobj){ if(kvobj){
successcb && successcb(kvobj); successcb && successcb(kvobj);
}else{ }else{
failcb && failcb(0, -1, "kvlist is not obj"); failcb && failcb(0, -1, "kvlist is not obj");
} }
}else{ }else{
//console.log('[__getStorage]failed!'+obj.errcode+":"+obj.errmsg); //console.log('[__getStorage]failed!'+obj.errcode+":"+obj.errmsg);
failcb && failcb(0, obj.errcode, obj.errmsg); failcb && failcb(0, obj.errcode, obj.errmsg);
} }
}, function(errcode, errmsg){ }, function(errcode, errmsg){
//console.log('[__getStorage]failed!'+errcode+":"+errmsg); //console.log('[__getStorage]failed!'+errcode+":"+errmsg);
failcb && failcb(errcode, 0, errmsg); failcb && failcb(errcode, 0, errmsg);
}); });
}, },
__getExpireTime(accountid, sessionid, token, skey, successcb, failcb){ __getExpireTime(accountid, sessionid, token, skey, successcb, failcb){
this.urlbd.clear(); this.urlbd.clear();
this.urlbd.addKV('c', 'CloudStorage') this.urlbd.addKV('c', 'CloudStorage')
.addKV('a', 'ttl') .addKV('a', 'ttl')
.addKV('account_id', accountid) .addKV('account_id', accountid)
.addKV('session_id', sessionid) .addKV('session_id', sessionid)
.addKV('access_token', token) .addKV('access_token', token)
.addKV('keys', skey); .addKV('keys', skey);
httpclient.httpGet(this.urlbd.baseurl, function(restext){ httpclient.httpGet(this.urlbd.baseurl, function(restext){
var obj = httpclient.JSON_parse(restext); var obj = httpclient.JSON_parse(restext);
if(obj.errcode == 0){ if(obj.errcode == 0){
//console.log('[__getExpireTime]success!'+JSON.stringify(obj)); //console.log('[__getExpireTime]success!'+JSON.stringify(obj));
var ktobj = httpclient.JSON_parse(obj.KTList); var ktobj = httpclient.JSON_parse(obj.KTList);
if(ktobj){ if(ktobj){
successcb && successcb(ktobj); successcb && successcb(ktobj);
}else{ }else{
failcb && failcb(0, -1, "kvlist is not obj"); failcb && failcb(0, -1, "kvlist is not obj");
} }
}else{ }else{
//console.log('[__getExpireTime]failed!'+obj.errcode+":"+obj.errmsg); //console.log('[__getExpireTime]failed!'+obj.errcode+":"+obj.errmsg);
failcb && failcb(0, obj.errcode, obj.errmsg); failcb && failcb(0, obj.errcode, obj.errmsg);
} }
}, function(errcode, errmsg){ }, function(errcode, errmsg){
//console.log('[__getExpireTime]failed!'+errcode+":"+errmsg); //console.log('[__getExpireTime]failed!'+errcode+":"+errmsg);
failcb && failcb(errcode, 0, errmsg); failcb && failcb(errcode, 0, errmsg);
}); });
}, },
__setStorage(accountid, sessionid, token, kvlist, successcb, failcb){ __setStorage(accountid, sessionid, token, kvlist, successcb, failcb){
this.urlbd.clear(); this.urlbd.clear();
this.urlbd.addKV('c', 'CloudStorage') this.urlbd.addKV('c', 'CloudStorage')
.addKV('a', 'setStorage') .addKV('a', 'setStorage')
.addKV('account_id', accountid) .addKV('account_id', accountid)
.addKV('session_id', sessionid) .addKV('session_id', sessionid)
.addKV('access_token', token); .addKV('access_token', token);
let value = JSON.stringify(kvlist); let value = JSON.stringify(kvlist);
httpclient.httpPost(this.urlbd.baseurl, value, function(restext){ httpclient.httpPost(this.urlbd.baseurl, value, function(restext){
let obj = httpclient.JSON_parse(restext); let obj = httpclient.JSON_parse(restext);
if(obj.errcode == 0){ if(obj.errcode == 0){
//console.log('[__setStorage]success!'+JSON.stringify(obj)); //console.log('[__setStorage]success!'+JSON.stringify(obj));
successcb && successcb(); successcb && successcb();
}else{ }else{
//console.log('[__setStorage]failed!'+obj.errcode+":"+obj.errmsg); //console.log('[__setStorage]failed!'+obj.errcode+":"+obj.errmsg);
failcb && failcb(0, obj.errcode, obj.errmsg); failcb && failcb(0, obj.errcode, obj.errmsg);
} }
}, function(errcode, errmsg){ }, function(errcode, errmsg){
//console.log('[__setStorage]failed!'+errcode+":"+errmsg); //console.log('[__setStorage]failed!'+errcode+":"+errmsg);
failcb && failcb(errcode, 0, errmsg); failcb && failcb(errcode, 0, errmsg);
}); });
}, },
__setExpireTime(accountid, sessionid, token, skey, origntype, timevalue, successcb, failcb){ __setExpireTime(accountid, sessionid, token, skey, origntype, timevalue, successcb, failcb){
this.urlbd.clear(); this.urlbd.clear();
this.urlbd.addKV('c', 'CloudStorage') this.urlbd.addKV('c', 'CloudStorage')
.addKV('a', 'expire') .addKV('a', 'expire')
.addKV('account_id', accountid) .addKV('account_id', accountid)
.addKV('session_id', sessionid) .addKV('session_id', sessionid)
.addKV('access_token', token) .addKV('access_token', token)
.addKV('keys', skey) .addKV('keys', skey)
.addKV('time_origin', origntype) .addKV('time_origin', origntype)
.addKV('time_val', timevalue); .addKV('time_val', timevalue);
httpclient.httpGet(this.urlbd.baseurl, function(restext){ httpclient.httpGet(this.urlbd.baseurl, function(restext){
let obj = httpclient.JSON_parse(restext); let obj = httpclient.JSON_parse(restext);
if(obj.errcode == 0){ if(obj.errcode == 0){
//console.log('[__delStorage]success!'+JSON.stringify(obj)); //console.log('[__delStorage]success!'+JSON.stringify(obj));
successcb && successcb(); successcb && successcb();
}else{ }else{
//console.log('[__delStorage]failed!'+obj.errcode+":"+obj.errmsg); //console.log('[__delStorage]failed!'+obj.errcode+":"+obj.errmsg);
failcb && failcb(0, obj.errcode, obj.errmsg); failcb && failcb(0, obj.errcode, obj.errmsg);
} }
}, function(errcode, errmsg){ }, function(errcode, errmsg){
//console.log('[__delStorage]failed!'+errcode+":"+errmsg); //console.log('[__delStorage]failed!'+errcode+":"+errmsg);
failcb && failcb(errcode, 0, errmsg); failcb && failcb(errcode, 0, errmsg);
}); });
}, },
__clearStorage(accountid, sessionid, token, successcb, failcb){ __clearStorage(accountid, sessionid, token, successcb, failcb){
this.urlbd.clear(); this.urlbd.clear();
this.urlbd.addKV('c', 'CloudStorage') this.urlbd.addKV('c', 'CloudStorage')
.addKV('a', 'clearStorage') .addKV('a', 'clearStorage')
.addKV('account_id', accountid) .addKV('account_id', accountid)
.addKV('session_id', sessionid) .addKV('session_id', sessionid)
.addKV('access_token', token); .addKV('access_token', token);
httpclient.httpGet(this.urlbd.baseurl, function(restext){ httpclient.httpGet(this.urlbd.baseurl, function(restext){
let obj = httpclient.JSON_parse(restext); let obj = httpclient.JSON_parse(restext);
if(obj.errcode == 0){ if(obj.errcode == 0){
//console.log('[__clearStorage]success!'+JSON.stringify(obj)); //console.log('[__clearStorage]success!'+JSON.stringify(obj));
successcb && successcb(); successcb && successcb();
}else{ }else{
//console.log('[__clearStorage]failed!'+obj.errcode+":"+obj.errmsg); //console.log('[__clearStorage]failed!'+obj.errcode+":"+obj.errmsg);
failcb && failcb(0, obj.errcode, obj.errmsg); failcb && failcb(0, obj.errcode, obj.errmsg);
} }
}, function(errcode, errmsg){ }, function(errcode, errmsg){
//console.log('[__clearStorage]failed!'+errcode+":"+errmsg); //console.log('[__clearStorage]failed!'+errcode+":"+errmsg);
failcb && failcb(errcode, 0, errmsg); failcb && failcb(errcode, 0, errmsg);
}); });
}, },
__delStorage(accountid, sessionid, token, skey, successcb, failcb){ __delStorage(accountid, sessionid, token, skey, successcb, failcb){
this.urlbd.clear(); this.urlbd.clear();
this.urlbd.addKV('c', 'CloudStorage') this.urlbd.addKV('c', 'CloudStorage')
.addKV('a', 'delKeys') .addKV('a', 'delKeys')
.addKV('account_id', accountid) .addKV('account_id', accountid)
.addKV('session_id', sessionid) .addKV('session_id', sessionid)
.addKV('access_token', token) .addKV('access_token', token)
.addKV('keys', skey); .addKV('keys', skey);
httpclient.httpGet(this.urlbd.baseurl, function(restext){ httpclient.httpGet(this.urlbd.baseurl, function(restext){
let obj = httpclient.JSON_parse(restext); let obj = httpclient.JSON_parse(restext);
if(obj.errcode == 0){ if(obj.errcode == 0){
//console.log('[__delStorage]success!'+JSON.stringify(obj)); //console.log('[__delStorage]success!'+JSON.stringify(obj));
successcb && successcb(); successcb && successcb();
}else{ }else{
//console.log('[__delStorage]failed!'+obj.errcode+":"+obj.errmsg); //console.log('[__delStorage]failed!'+obj.errcode+":"+obj.errmsg);
failcb && failcb(0, obj.errcode, obj.errmsg); failcb && failcb(0, obj.errcode, obj.errmsg);
} }
}, function(errcode, errmsg){ }, function(errcode, errmsg){
//console.log('[__delStorage]failed!'+errcode+":"+errmsg); //console.log('[__delStorage]failed!'+errcode+":"+errmsg);
failcb && failcb(errcode, 0, errmsg); failcb && failcb(errcode, 0, errmsg);
}); });
}, },
__getShareConfig(accountid, sessionid, gameid, sex, province, city, successcb, failcb){ __getShareConfig(accountid, sessionid, gameid, sex, province, city, successcb, failcb){
this.urlbd.clear(); this.urlbd.clear();
this.urlbd.addKV('c', 'Config') this.urlbd.addKV('c', 'Config')
.addKV('a', 'share') .addKV('a', 'share')
.addKV('account_id', accountid) .addKV('account_id', accountid)
.addKV('session_id', sessionid) .addKV('session_id', sessionid)
.addKV('gameid', gameid) .addKV('gameid', gameid)
.addKV('sex', sex) .addKV('sex', sex)
.addKV('province', province) .addKV('province', province)
.addKV('city', city) .addKV('city', city)
; ;
httpclient.httpGet(this.urlbd.baseurl, function(restext){ httpclient.httpGet(this.urlbd.baseurl, function(restext){
let obj = httpclient.JSON_parse(restext); let obj = httpclient.JSON_parse(restext);
if(obj.errcode == 0){ if(obj.errcode == 0){
//console.log('[__getShareConfig]success!'+JSON.stringify(obj)); //console.log('[__getShareConfig]success!'+JSON.stringify(obj));
successcb && successcb(obj.share_info); successcb && successcb(obj.share_info);
}else{ }else{
//console.log('[__getShareConfig]failed!'+obj.errcode+":"+obj.errmsg); //console.log('[__getShareConfig]failed!'+obj.errcode+":"+obj.errmsg);
failcb && failcb(0, obj.errcode, obj.errmsg); failcb && failcb(0, obj.errcode, obj.errmsg);
} }
}, function(errcode, errmsg){ }, function(errcode, errmsg){
//console.log('[__getShareConfig]failed!'+errcode+":"+errmsg); //console.log('[__getShareConfig]failed!'+errcode+":"+errmsg);
failcb && failcb(errcode, 0, errmsg); failcb && failcb(errcode, 0, errmsg);
}); });
}, },
init(channelid, gameid, isoffical, owner, url){ init(channelid, gameid, isoffical, owner, url){
this.gameid = gameid; this.gameid = gameid;
this.channelid = channelid; this.channelid = channelid;
this.token = ''; this.token = '';
this.urlbd = new urlbuilder(url); this.urlbd = new urlbuilder(url);
this.cfg = { this.cfg = {
_reborntype: -1, _reborntype: -1,
_getrewardtype: -1, _getrewardtype: -1,
_exchange_rewardtype: -1, _exchange_rewardtype: -1,
_navigateflag: -1, _navigateflag: -1,
_serverversion: -1, _serverversion: -1,
_gglFlag: -1 _gglFlag: -1
}; };
this.cfginited = false; this.cfginited = false;
//console.log("[jccloud]init:"+gameid + "|" + channelid + "|" + isoffical); //console.log("[jccloud]init:"+gameid + "|" + channelid + "|" + isoffical);
}, },
setAccountID(accountid, sessionid){ setAccountID(accountid, sessionid){
this.accountid = accountid; this.accountid = accountid;
this.sessionid = sessionid; this.sessionid = sessionid;
}, },
setNickName(nickname){ setNickName(nickname){
this.nickname = nickname; this.nickname = nickname;
}, },
setFromAppID(appid){ setFromAppID(appid){
this.fromid = appid; this.fromid = appid;
}, },
setLocalUUID(uuid){ setLocalUUID(uuid){
this.localid = uuid; this.localid = uuid;
}, },
setSystemInfo(info){ setSystemInfo(info){
}, },
setUserInfo(info){ setUserInfo(info){
this.userinfo = info; this.userinfo = info;
}, },
getConfig(successcb, failcb){ getConfig(successcb, failcb){
if(this._configgetting){ if(this._configgetting){
return 1; return 1;
} }
this._configgetting = true; this._configgetting = true;
this.__getConfig(this.accountid, this.sessionid, this.channelid, this.gameid, 'read', (kvlist) => { this.__getConfig(this.accountid, this.sessionid, this.channelid, this.gameid, 'read', (kvlist) => {
this._configgetting = false; this._configgetting = false;
successcb && successcb(kvlist); successcb && successcb(kvlist);
}, (neterr, logicerr, errmsg) => { }, (neterr, logicerr, errmsg) => {
this._configgetting = false; this._configgetting = false;
failcb && failcb(neterr, logicerr, errmsg); failcb && failcb(neterr, logicerr, errmsg);
}); });
return 0; return 0;
}, },
initConfig(successcb, failcb){ initConfig(successcb, failcb){
if(this.cfginited){ if(this.cfginited){
successcb && successcb(this.cfg); successcb && successcb(this.cfg);
return 0; return 0;
} }
this.cfginited = false; this.cfginited = false;
return this.getConfig((res) => { return this.getConfig((res) => {
//console.log(JSON.stringify(res)); //console.log(JSON.stringify(res));
if(res instanceof Array){ if(res instanceof Array){
res.forEach(element => { res.forEach(element => {
if(element.key == 'reborn'){ if(element.key == 'reborn'){
this.cfg._reborntype = element.value; this.cfg._reborntype = element.value;
}else if(element.key == 'share_reward'){ }else if(element.key == 'share_reward'){
this.cfg._getrewardtype = element.value; this.cfg._getrewardtype = element.value;
}else if(element.key == 'exchange_reward'){ }else if(element.key == 'exchange_reward'){
this.cfg._exchange_rewardtype = element.value; this.cfg._exchange_rewardtype = element.value;
}else if(element.key == 'navigate'){ }else if(element.key == 'navigate'){
this.cfg._navigateflag = element.value; this.cfg._navigateflag = element.value;
}else if(element.key == 'version'){ }else if(element.key == 'version'){
this.cfg._serverversion = element.value; this.cfg._serverversion = element.value;
}else if(element.key == 'ggl'){ }else if(element.key == 'ggl'){
this.cfg._gglFlag = element.value; this.cfg._gglFlag = element.value;
}else if(element.key == 'festival'){ }else if(element.key == 'festival'){
this.cfg._festivalFlag = element.value; this.cfg._festivalFlag = element.value;
}else{ }else{
this.cfg[element.key] = element.value; this.cfg[element.key] = element.value;
} }
}); });
this.cfginited = true; this.cfginited = true;
successcb && successcb(this.cfg); successcb && successcb(this.cfg);
}else{ }else{
failcb && failcb(0, -1, ''); failcb && failcb(0, -1, '');
} }
}, (neterr, logicerr, errmsg) =>{ }, (neterr, logicerr, errmsg) =>{
failcb && failcb(neterr, logicerr, errmsg); failcb && failcb(neterr, logicerr, errmsg);
}); });
}, },
getPrivateConfig(successcb, failcb){ getPrivateConfig(successcb, failcb){
if(this._pvconfiggetting){ if(this._pvconfiggetting){
return 1; return 1;
} }
this._pvconfiggetting = true; this._pvconfiggetting = true;
this.__getConfig(this.accountid, this.sessionid, this.channelid, this.gameid, 'readPrivate', (kvlist) => { this.__getConfig(this.accountid, this.sessionid, this.channelid, this.gameid, 'readPrivate', (kvlist) => {
this._pvconfiggetting = false; this._pvconfiggetting = false;
successcb && successcb(kvlist); successcb && successcb(kvlist);
}, (neterr, logicerr, errmsg) => { }, (neterr, logicerr, errmsg) => {
this._pvconfiggetting = false; this._pvconfiggetting = false;
failcb && failcb(neterr, logicerr, errmsg); failcb && failcb(neterr, logicerr, errmsg);
}); });
return 0; return 0;
}, },
initPrivateConfig(successcb, failcb){ initPrivateConfig(successcb, failcb){
if(this.pvcfginited){ if(this.pvcfginited){
successcb && successcb(this.pvcfg); successcb && successcb(this.pvcfg);
return 0; return 0;
} }
this.pvcfginited = false; this.pvcfginited = false;
return this.getPrivateConfig((res) => { return this.getPrivateConfig((res) => {
//console.log(JSON.stringify(res)); //console.log(JSON.stringify(res));
if(res instanceof Array){ if(res instanceof Array){
res.forEach(element => { res.forEach(element => {
this.pvcfg[element.key] = element.value; this.pvcfg[element.key] = element.value;
}); });
this.pvcfginited = true; this.pvcfginited = true;
successcb && successcb(this.pvcfg); successcb && successcb(this.pvcfg);
}else{ }else{
failcb && failcb(0, -1, ''); failcb && failcb(0, -1, '');
} }
}, (neterr, logicerr, errmsg) =>{ }, (neterr, logicerr, errmsg) =>{
failcb && failcb(neterr, logicerr, errmsg); failcb && failcb(neterr, logicerr, errmsg);
}); });
}, },
// 获取服务器配置 // 获取服务器配置
getServerConfig(successcb, failcb, bForce){ getServerConfig(successcb, failcb, bForce){
if(bForce){ if(bForce){
this.cfginited = false; this.cfginited = false;
} }
return this.initConfig(successcb, failcb); return this.initConfig(successcb, failcb);
}, },
getPrivateConfig(successcb, failcb){ getPrivateConfig(successcb, failcb){
if(bForce){ if(bForce){
this.pvcfginited = false; this.pvcfginited = false;
} }
return this.initPrivateConfig(successcb, failcb); return this.initPrivateConfig(successcb, failcb);
}, },
getShareConfig(successcb, failcb){ getShareConfig(successcb, failcb){
if(this.userinfo){ if(this.userinfo){
this.__getShareConfig(this.accountid, this.sessionid, this.gameid, this.__getShareConfig(this.accountid, this.sessionid, this.gameid,
this.userinfo.sex, this.userinfo.province, this.userinfo.city, successcb, failcb); this.userinfo.sex, this.userinfo.province, this.userinfo.city, successcb, failcb);
}else{ }else{
this.__getShareConfig(this.accountid, this.sessionid, this.gameid, this.__getShareConfig(this.accountid, this.sessionid, this.gameid,
0, '', '', successcb, failcb); 0, '', '', successcb, failcb);
} }
}, },
setStorage: function(skey, svalue, successcb, failcb, timeorign_type, time_value){ setStorage: function(skey, svalue, successcb, failcb, timeorign_type, time_value){
let obj = { let obj = {
key: skey, key: skey,
value: svalue value: svalue
}; };
if(timeorign_type && time_value){ if(timeorign_type && time_value){
obj.time_origin = timeorign_type; obj.time_origin = timeorign_type;
obj.time_val = time_value; obj.time_val = time_value;
} }
let lst = [obj]; let lst = [obj];
this.__setStorage(this.accountid, this.sessionid, this.token, lst, successcb, failcb); this.__setStorage(this.accountid, this.sessionid, this.token, lst, successcb, failcb);
}, },
setStorages: function(kvlist, successcb, failcb){ setStorages: function(kvlist, successcb, failcb){
this.__setStorage(this.accountid, this.sessionid, this.token, kvlist, successcb, failcb); this.__setStorage(this.accountid, this.sessionid, this.token, kvlist, successcb, failcb);
}, },
getStorage: function(key, successcb, failcb){ getStorage: function(key, successcb, failcb){
this.__getStorage(this.accountid, this.sessionid, this.token, key, (kvlist) => { this.__getStorage(this.accountid, this.sessionid, this.token, key, (kvlist) => {
if(kvlist.length > 0){ if(kvlist.length > 0){
let obj = kvlist[0]; let obj = kvlist[0];
successcb && successcb(obj.value, obj.ttl_seconds, obj.key); successcb && successcb(obj.value, obj.ttl_seconds, obj.key);
}else{ }else{
successcb && successcb(null, -1, key); successcb && successcb(null, -1, key);
} }
}, failcb); }, failcb);
}, },
getStorages: function(keylist, successcb, failcb){ getStorages: function(keylist, successcb, failcb){
let skey = keylist.join(); let skey = keylist.join();
this.__getStorage(this.accountid, this.sessionid, this.token, skey, successcb, failcb); this.__getStorage(this.accountid, this.sessionid, this.token, skey, successcb, failcb);
}, },
delStorage: function(key, successcb, failcb){ delStorage: function(key, successcb, failcb){
this.__delStorage(this.accountid, this.sessionid, this.token, key, successcb, failcb); this.__delStorage(this.accountid, this.sessionid, this.token, key, successcb, failcb);
}, },
delStorages: function(keylist, successcb, failcb){ delStorages: function(keylist, successcb, failcb){
let skey = keylist.join(); let skey = keylist.join();
this.__delStorage(this.accountid, this.sessionid, this.token, skey, successcb, failcb); this.__delStorage(this.accountid, this.sessionid, this.token, skey, successcb, failcb);
}, },
clearStorage: function(successcb, failcb){ clearStorage: function(successcb, failcb){
this.__clearStorage(this.accountid, this.sessionid, this.token, successcb, failcb); this.__clearStorage(this.accountid, this.sessionid, this.token, successcb, failcb);
}, },
setExpireTime: function(key, timeorign_type, time_value, successcb, failcb){ setExpireTime: function(key, timeorign_type, time_value, successcb, failcb){
this.__setExpireTime(this.accountid, this.sessionid, this.token, key, timeorign_type, time_value, successcb, failcb); this.__setExpireTime(this.accountid, this.sessionid, this.token, key, timeorign_type, time_value, successcb, failcb);
}, },
setExpireTimes: function(keylist, timeorign_type, time_value, successcb, failcb){ setExpireTimes: function(keylist, timeorign_type, time_value, successcb, failcb){
let skey = keylist.join(); let skey = keylist.join();
this.__setExpireTime(this.accountid, this.sessionid, this.token, skey, timeorign_type, time_value, successcb, failcb); this.__setExpireTime(this.accountid, this.sessionid, this.token, skey, timeorign_type, time_value, successcb, failcb);
}, },
getExpireTime: function(key, successcb, failcb){ getExpireTime: function(key, successcb, failcb){
this.__getStorage(this.accountid, this.sessionid, this.token, key, (ktlist) => { this.__getStorage(this.accountid, this.sessionid, this.token, key, (ktlist) => {
if(ktlist.length > 0){ if(ktlist.length > 0){
let obj = ktlist[0]; let obj = ktlist[0];
successcb && successcb(obj.ttl_seconds, obj.key); successcb && successcb(obj.ttl_seconds, obj.key);
}else{ }else{
successcb && successcb(-1, key); successcb && successcb(-1, key);
} }
}, failcb); }, failcb);
}, },
getExpireTimes: function(key, successcb, failcb){ getExpireTimes: function(key, successcb, failcb){
this.__getStorage(this.accountid, this.sessionid, this.token, key, successcb, failcb); this.__getStorage(this.accountid, this.sessionid, this.token, key, successcb, failcb);
}, },
getShareData(psex,pprovince,pcity ,successcb, failcb){ getShareData(psex,pprovince,pcity ,successcb, failcb){
this.urlbd.clear(); this.urlbd.clear();
this.urlbd.addKV('c', 'Config') this.urlbd.addKV('c', 'Config')
.addKV('a', 'share') .addKV('a', 'share')
.addKV('gameid', this.gameid) .addKV('gameid', this.gameid)
.addKV('sex', psex) .addKV('sex', psex)
.addKV('province', pprovince) .addKV('province', pprovince)
.addKV('city', pcity) .addKV('city', pcity)
.addKV('account_id', this.accountid) .addKV('account_id', this.accountid)
.addKV('session_id', this.sessionid) .addKV('session_id', this.sessionid)
.addKV('access_token', this.token); .addKV('access_token', this.token);
httpclient.httpGet(this.urlbd.baseurl, function(restext){ httpclient.httpGet(this.urlbd.baseurl, function(restext){
let obj = httpclient.JSON_parse(restext); let obj = httpclient.JSON_parse(restext);
if(obj.errcode == 0){ if(obj.errcode == 0){
successcb && successcb(obj.share_info); successcb && successcb(obj.share_info);
}else{ }else{
//console.log('[__delStorage]failed!'+obj.errcode+":"+obj.errmsg); //console.log('[__delStorage]failed!'+obj.errcode+":"+obj.errmsg);
failcb && failcb(); failcb && failcb();
} }
}, function(errcode, errmsg){ }, function(errcode, errmsg){
//console.log('[__delStorage]failed!'+errcode+":"+errmsg); //console.log('[__delStorage]failed!'+errcode+":"+errmsg);
failcb && failcb(); failcb && failcb();
}); });
}, },
}; };

View File

@ -124,7 +124,7 @@
this.gid = decodeURIComponent(params.gid); this.gid = decodeURIComponent(params.gid);
} }
onShow() { onShow() {
jcEvent.on(jcEvent.events.NEED_UPDATE_CFG, this, data => { jcEvent.on(jcEvent.events.LOGIN_FINISHED, this, data => {
this.loadCfg(); this.loadCfg();
this.$apply(); this.$apply();
}) })

133
src/pages/io.wpy Normal file
View File

@ -0,0 +1,133 @@
<style lang="less">
.qrimg_content {
display: flex;
position: absolute;
width: 100%;
height: 300px;
top: 0;
justify-content: center;
background-color: white;
}
#myQrcode{
}
</style>
<template>
<view class="qrimg_content">
<canvas style="width: 300px; height: 300px;" canvas-id="myQrcode"></canvas>
</view>
<view class="qrimg_content">
<image class="qrimg" @tap="imageTap" src="{{imgData}}" show-menu-by-longpress style="width: 300px; height:300px;"></image>
</view>
</template>
<script>
import wepy from 'wepy';
import cfg from '../mixins/cfg';
import http from '../utils/http';
import g from '../common/global';
import jcEvent from '../common/jc-event';
let sdkManage = require('../jcfw/SDKManage');
export default class ProductPage extends wepy.page {
mixins = [cfg];
components = {
};
config = {
navigationBarTitleText: '购买产品'
};
data = {
imgData: ''
};
methods = {
imageTap: function(e) {
wepy.previewImage({
current: this.imgData,
urls: [this.imgData]
});
},
};
async onLoad(params) {
console.log('io page onload,', params);
if (this.$parent.globalData.isPay) {
if (sdkManage.session_id) {
this.prePay();
} else {
jcEvent.on(jcEvent.events.LOGIN_FINISHED, this, data => {
this.prePay();
})
}
} else {
wepy.reLaunch({
url: '/pages/index'
})
}
}
onShow(){
}
async prePay() {
wepy.showLoading({
title: '支付中'
});
this.payData = this.$parent.globalData.extraData;
if (this.payData) {
let url = `${g.payUrl(this.payData.isoffical)}&session_id=${sdkManage.session_id}&account_id=${sdkManage.account_id}&data=${encodeURIComponent(this.payData.data)}`
sdkManage.gamelog.logButtonClick('pay', {data: this.payData}, 'payBegin');
try {
let res = await http.get(url);
if (res.errcode === 0) {
let payInfo = JSON.parse(res.pay_str);
this.orderId = res.orderid;
console.log(payInfo);
this.beginPay(payInfo);
}
this.$apply();
} catch (err) {
sdkManage.gamelog.logButtonClick('pay', {data: this.payData, errMsg: 'requestPayment:fail prepay'}, 'parError');
wepy.hideLoading();
this.backToApp('requestPayment:fail prepay');
}
} else {
wepy.hideLoading();
sdkManage.gamelog.logButtonClick('pay', {errMsg: 'requestPayment:fail no pay data'}, 'parError');
}
}
beginPay(payInfo) {
let self = this;
wx.requestPayment({
'timeStamp': payInfo.timeStamp,
'nonceStr': payInfo.nonceStr,
'package': payInfo.package,
'signType': payInfo.signType,
'paySign': payInfo.paySign,
complete: (res) => {
wepy.hideLoading();
console.log('支付结果:', res);
if (res.errMsg === 'requestPayment:ok') {
console.log('支付成功')
sdkManage.gamelog.logButtonClick('pay', {data: self.payData, orderId: self.orderId}, 'parSuccess');
} else if (res.errMsg === 'requestPayment:fail cancel' || res.errMsg === 'requestPayment:cancel') {
sdkManage.gamelog.logButtonClick('pay', {data: self.payData, orderId: self.orderId, errMsg: res.errMsg}, 'parError');
} else {
console.log('支付失败');
sdkManage.gamelog.logButtonClick('pay', {data: self.payData, orderId: self.orderId, errMsg: res.errMsg}, 'parError');
}
self.backToApp(res.errMsg);
}
})
}
backToApp(errMsg) {
wepy.navigateBackMiniProgram({
extraData: {
payData: errMsg,
orderid: this.orderId
},
complete: (res) => {
console.log('navigateBackMiniProgram success, now to index');
}
})
}
}
</script>

View File

@ -81,7 +81,7 @@
}; };
async onLoad(params) { async onLoad(params) {
jcEvent.on(jcEvent.events.NEED_UPDATE_CFG, this, data => { jcEvent.on(jcEvent.events.LOGIN_FINISHED, this, data => {
this.loadCfg(); this.loadCfg();
this.$apply(); this.$apply();
}) })

View File

@ -15,7 +15,7 @@ const post = (url, data, header) => {
} }
const Ajax = (url, method, data, header) => { const Ajax = (url, method, data, header) => {
url = g.apiBase + url url = url.startsWith('http') ? url : g.apiBase + url;
header = header || {} header = header || {}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {