Commit 0d5730c6 authored by liuxinjun's avatar liuxinjun

初始化

parents
#/////////////////////////////////////////////////////////////////////////////
# Fireball Projects
#/////////////////////////////////////////////////////////////////////////////
library/
temp/
local/
build/
#/////////////////////////////////////////////////////////////////////////////
# Logs and databases
#/////////////////////////////////////////////////////////////////////////////
*.log
*.sql
*.sqlite
#/////////////////////////////////////////////////////////////////////////////
# files for debugger
#/////////////////////////////////////////////////////////////////////////////
*.sln
*.csproj
*.pidb
*.unityproj
*.suo
#/////////////////////////////////////////////////////////////////////////////
# OS generated files
#/////////////////////////////////////////////////////////////////////////////
.DS_Store
ehthumbs.db
Thumbs.db
#/////////////////////////////////////////////////////////////////////////////
# exvim files
#/////////////////////////////////////////////////////////////////////////////
*UnityVS.meta
*.err
*.err.meta
*.exvim
*.exvim.meta
*.vimentry
*.vimentry.meta
*.vimproject
*.vimproject.meta
.vimfiles.*/
.exvim.*/
quick_gen_project_*_autogen.bat
quick_gen_project_*_autogen.bat.meta
quick_gen_project_*_autogen.sh
quick_gen_project_*_autogen.sh.meta
.exvim.app
#/////////////////////////////////////////////////////////////////////////////
# webstorm files
#/////////////////////////////////////////////////////////////////////////////
.idea/
#//////////////////////////
# VS Code
#//////////////////////////
.vscode/
\ No newline at end of file
{
"ver": "1.0.1",
"uuid": "0e68c117-868a-4135-bc3b-cc9209633219",
"subMetas": {}
}
\ No newline at end of file
exports.app_key = "778fe3a3df9f2fad46f85b885ed9ec7b"; //请在此行填写从阿拉丁后台获取的appkey
exports.getLocation = false; //默认不获取用户坐标位置
\ No newline at end of file
{
"ver": "1.0.5",
"uuid": "85f99ca3-1908-410d-b4c5-3fc10c72409e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
!
function() {
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
function e() {
return new Promise(function(e, n) {
wx.getSetting({
success: function(n) {
n.authSetting["scope.userInfo"] ? wx.getUserInfo({
success: function(n) {
M = c(n.userInfo.avatarUrl.split("/")),
e(n)
},
fail: function() {
e("")
}
}) : e("")
},
fail: function() {
e("")
}
})
})
}
function n() {
return new Promise(function(e, n) {
wx.getNetworkType({
success: function(n) {
e(n)
},
fail: function() {
e("")
}
})
})
}
function t() {
return new Promise(function(e, n) {
"1044" == y.scene ? wx.getShareInfo({
shareTicket: y.shareTicket,
success: function(n) {
e(n)
},
fail: function() {
e("")
}
}) : e("")
})
}
function r() {
return new Promise(function(e, n) {
d.getLocation ? wx.getLocation({
success: function(n) {
e(n)
},
fail: function() {
e("")
}
}) : wx.getSetting({
success: function(n) {
n.authSetting["scope.userLocation"] ? (wx.getLocation({
success: function(n) {
e(n)
},
fail: function() {
e("")
}
}), e("")) : e("")
},
fail: function() {
e("")
}
})
})
}
function a() {
function e() {
return Math.floor(65536 * (1 + Math.random())).toString(16).substring(1)
}
return e() + e() + e() + e() + e() + e() + e() + e()
}
function o(e, n) {
var t = 0,
r = function() {
v++,
e.as = m,
e.at = x,
e.rq_c = v,
e.ifo = l,
e.ak = d.app_key,
e.uu = h,
e.v = u,
e.st = Date.now(),
e.ev = n,
e.wsr = y,
e.ufo = s(e.ufo),
e.ec = _,
wx.request({
url: "https://" + f + ".aldwx.com/d.html",
data: e,
header: {
se: w || "",
op: p || "",
img: M || ""
},
method: "GET",
fail: function() {
t < 2 && (t++, e.retryTimes = t, r())
}
})
};
r()
}
function s(e) {
if (void 0 === e || "" === e) return "";
var n = {};
for (var t in e)"rawData" != t && "errMsg" != t && (n[t] = e[t]);
return n
}
function i(e) {
var n = {};
for (var t in e) n[t] = e[t];
return n
}
function c(e) {
for (var n = "",
t = 0; t < e.length; t++) e[t].length > n.length && (n = e[t]);
return n
}
var u = "1.0.0",
f = "glog",
d = require("./ald-game-conf");
"" === d.app_key && console.error("请在配置文件中填写您的app_key"),
d.app_key = d.app_key.replace(/\s/g, ""),
function() {
wx.request({
url: "https://" + f + ".aldwx.com/config/app.json",
method: "GET",
success: function(e) {
200 === e.statusCode && (e.data.version != u && console.warn("您的SDK不是最新版本,请尽快升级!"), e.data.warn && console.warn(e.data.warn), e.data.error && console.error(e.data.error))
}
})
} ();
var l = "",
h = function() {
var e = "";
try {
e = wx.getStorageSync("aldstat_uuid"),
wx.setStorageSync("ald_ifo", !0)
} catch(n) {
e = "uuid_getstoragesync"
}
if (e) l = !1;
else {
e = a(),
l = !0;
try {
wx.setStorageSync("aldstat_uuid", e)
} catch(e) {
wx.setStorageSync("aldstat_uuid", "uuid_getstoragesync")
}
}
return e
} (),
g = {},
w = "",
p = "",
_ = 0,
v = "",
y = wx.getLaunchOptionsSync(),
S = Date.now(),
x = "" + Date.now() + Math.floor(1e7 * Math.random()),
m = "" + Date.now() + Math.floor(1e7 * Math.random()),
q = 0,
k = "",
M = "",
b = !0,
O = ["aldSendEvent", "aldOnShareAppMeassage", "aldShareAppMessage", "aldSendSession", "aldSendOpenid"]; (function() {
return Promise.all([e(), n(), r()])
})().then(function(e) {
"" !== e[2] ? (g.lat = e[2].latitude || "", g.lng = e[2].longitude || "", g.spd = e[2].speed || "") : (g.lat = "", g.lng = "", g.spd = ""),
"" !== e[1] ? g.nt = e[1].networkType || "": g.nt = "";
var n = i(g);
"" !== e[0] && (n.ufo = e[0], k = e[0]),
o(n, "init")
}),
wx.onShow(function(e) {
y = e,
q = Date.now(),
b || (x = "" + Date.now() + Math.floor(1e7 * Math.random()), l = !1, wx.setStorageSync("ald_ifo", !1)),
b = !1;
var n = i(g);
i(g);
var r = i(g);
n.sm = q - S,
e.query.ald_share_src && e.shareTicket && "1044" === e.scene ? (r.tp = "ald_share_click", t().then(function(e) {
r.ct = e,
o(r, "event")
})) : e.query.ald_share_src && (r.tp = "ald_share_click", r.ct = "1", o(r, "event")),
o(n, "show")
}),
wx.onHide(function() {
var e = i(g);
e.dr = Date.now() - q,
"" === k ? wx.getSetting({
success: function(n) {
n.authSetting["scope.userInfo"] ? wx.getUserInfo({
success: function(n) {
e.ufo = n,
k = n,
M = c(n.userInfo.avatarUrl.split("/")),
o(e, "hide")
}
}) : o(e, "hide")
}
}) : o(e, "hide")
}),
wx.onError(function(e) {
var n = i(g);
n.tp = "ald_error_message",
n.ct = e,
_++,
o(n, "event")
});
for (var D = {
aldSendEvent: function(e, n) {
var t = i(g);
"" !== e && "string" == typeof e && e.length <= 255 ? (t.tp = e, "string" == typeof n && n.length <= 255 ? (t.ct = String(n), o(t, "event")) : "object" == typeof n ? (JSON.stringify(n).length >= 255 && console.error("自定义事件参数不能超过255个字符"), t.ct = JSON.stringify(n), o(t, "event")) : void 0 === n || "" === n ? o(t, "event") : console.error("事件参数必须为String,Object类型,且参数长度不能超过255个字符")) : console.error("事件名称必须为String类型且不能超过255个字符")
},
aldOnShareAppMeassage: function(e) {
wx.updateShareMenu({
withShareTicket: !0,
complete: function() {
wx.onShareAppMessage(function() {
var n = e(),
t = "";
t = void 0 !== y.query.ald_share_src ? void 0 !== n.query ? (y.query.ald_share_src.indexOf(h), n.query + "&ald_share_src=" + y.query.ald_share_src + "," + h) : (y.query.ald_share_src.indexOf(h), "ald_share_src=" + y.query.ald_share_src + "," + h) : void 0 !== n.query ? n.query + "&ald_share_src=" + h: "ald_share_src=" + h,
n.query = t;
var r = i(g);
return r.ct = n,
r.tp = "ald_share_status",
o(r, "event"),
n
})
}
})
},
aldShareAppMessage: function(e) {
var n = e,
t = "";
t = void 0 !== y.query.ald_share_src ? void 0 !== n.query ? (y.query.ald_share_src.indexOf(h), n.query + "&ald_share_src=" + y.query.ald_share_src + "," + h) : (y.query.ald_share_src.indexOf(h), "ald_share_src=" + y.query.ald_share_src + "," + h) : void 0 !== n.query ? n.query + "&ald_share_src=" + h: "ald_share_src=" + h,
n.query = t;
var r = i(g);
r.ct = n,
r.tp = "ald_share_status",
o(r, "event"),
wx.updateShareMenu({
withShareTicket: !0,
complete: function() {
wx.shareAppMessage(n)
}
})
},
aldSendSession: function(e) {
if ("" === e || !e) return void console.error("请传入从后台获取的session_key");
var n = i(g);
n.tp = "session",
n.ct = "session",
w = e,
"" === k ? wx.getSetting({
success: function(e) {
e.authSetting["scope.userInfo"] ? wx.getUserInfo({
success: function(e) {
n.ufo = e,
o(n, "event")
}
}) : o(n, "event")
}
}) : (n.ufo = k, "" !== k && (n.gid = ""), o(n, "event"))
},
aldSendOpenid: function(e) {
if ("" === e || !e) return void console.error("openID不能为空");
p = e;
var n = i(g);
n.tp = "openid",
n.ct = "openid",
o(n, "event")
}
},
I = 0; I < O.length; I++) !
function(e, n) {
Object.defineProperty(wx, e, {
value: n,
writable: !1,
enumerable: !0,
configurable: !0
})
} (O[I], D[O[I]]);
try {
var T = wx.getSystemInfoSync();
g.br = T.brand || "",
g.md = T.model,
g.pr = T.pixelRatio,
g.sw = T.screenWidth,
g.sh = T.screenHeight,
g.ww = T.windowWidth,
g.wh = T.windowHeight,
g.lang = T.language,
g.wv = T.version,
g.sv = T.system,
g.wvv = T.platform,
g.fs = T.fontSizeSetting,
g.wsdk = T.SDKVersion,
g.bh = T.benchmarkLevel || "",
g.bt = T.battery || "",
g.wf = T.wifiSignal || "",
g.lng = "",
g.lat = "",
g.nt = "",
g.spd = "",
g.ufo = ""
} catch(e) {}
}
} ();
\ No newline at end of file
{
"ver": "1.0.5",
"uuid": "9152f951-9a09-4139-b02b-022fdbbfc488",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
/*
* JavaScript MD5
* https://github.com/blueimp/JavaScript-MD5
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*
* Based on
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/
/* global define */
;(function ($) {
'use strict'
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safeAdd (x, y) {
var lsw = (x & 0xffff) + (y & 0xffff)
var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
return (msw << 16) | (lsw & 0xffff)
}
/*
* Bitwise rotate a 32-bit number to the left.
*/
function bitRotateLeft (num, cnt) {
return (num << cnt) | (num >>> (32 - cnt))
}
/*
* These functions implement the four basic operations the algorithm uses.
*/
function md5cmn (q, a, b, x, s, t) {
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b)
}
function md5ff (a, b, c, d, x, s, t) {
return md5cmn((b & c) | (~b & d), a, b, x, s, t)
}
function md5gg (a, b, c, d, x, s, t) {
return md5cmn((b & d) | (c & ~d), a, b, x, s, t)
}
function md5hh (a, b, c, d, x, s, t) {
return md5cmn(b ^ c ^ d, a, b, x, s, t)
}
function md5ii (a, b, c, d, x, s, t) {
return md5cmn(c ^ (b | ~d), a, b, x, s, t)
}
/*
* Calculate the MD5 of an array of little-endian words, and a bit length.
*/
function binlMD5 (x, len) {
/* append padding */
x[len >> 5] |= 0x80 << (len % 32)
x[((len + 64) >>> 9 << 4) + 14] = len
var i
var olda
var oldb
var oldc
var oldd
var a = 1732584193
var b = -271733879
var c = -1732584194
var d = 271733878
for (i = 0; i < x.length; i += 16) {
olda = a
oldb = b
oldc = c
oldd = d
a = md5ff(a, b, c, d, x[i], 7, -680876936)
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586)
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819)
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330)
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897)
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426)
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341)
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983)
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416)
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417)
c = md5ff(c, d, a, b, x[i + 10], 17, -42063)
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162)
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682)
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101)
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290)
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329)
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510)
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632)
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713)
b = md5gg(b, c, d, a, x[i], 20, -373897302)
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691)
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083)
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335)
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848)
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438)
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690)
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961)
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501)
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467)
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784)
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473)
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734)
a = md5hh(a, b, c, d, x[i + 5], 4, -378558)
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463)
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562)
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556)
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060)
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353)
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632)
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640)
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174)
d = md5hh(d, a, b, c, x[i], 11, -358537222)
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979)
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189)
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487)
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835)
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520)
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651)
a = md5ii(a, b, c, d, x[i], 6, -198630844)
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415)
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905)
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055)
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571)
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606)
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523)
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799)
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359)
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744)
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380)
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649)
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070)
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379)
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259)
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551)
a = safeAdd(a, olda)
b = safeAdd(b, oldb)
c = safeAdd(c, oldc)
d = safeAdd(d, oldd)
}
return [a, b, c, d]
}
/*
* Convert an array of little-endian words to a string
*/
function binl2rstr (input) {
var i
var output = ''
var length32 = input.length * 32
for (i = 0; i < length32; i += 8) {
output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xff)
}
return output
}
/*
* Convert a raw string to an array of little-endian words
* Characters >255 have their high-byte silently ignored.
*/
function rstr2binl (input) {
var i
var output = []
output[(input.length >> 2) - 1] = undefined
for (i = 0; i < output.length; i += 1) {
output[i] = 0
}
var length8 = input.length * 8
for (i = 0; i < length8; i += 8) {
output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << (i % 32)
}
return output
}
/*
* Calculate the MD5 of a raw string
*/
function rstrMD5 (s) {
return binl2rstr(binlMD5(rstr2binl(s), s.length * 8))
}
/*
* Calculate the HMAC-MD5, of a key and some data (raw strings)
*/
function rstrHMACMD5 (key, data) {
var i
var bkey = rstr2binl(key)
var ipad = []
var opad = []
var hash
ipad[15] = opad[15] = undefined
if (bkey.length > 16) {
bkey = binlMD5(bkey, key.length * 8)
}
for (i = 0; i < 16; i += 1) {
ipad[i] = bkey[i] ^ 0x36363636
opad[i] = bkey[i] ^ 0x5c5c5c5c
}
hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8)
return binl2rstr(binlMD5(opad.concat(hash), 512 + 128))
}
/*
* Convert a raw string to a hex string
*/
function rstr2hex (input) {
var hexTab = '0123456789abcdef'
var output = ''
var x
var i
for (i = 0; i < input.length; i += 1) {
x = input.charCodeAt(i)
output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f)
}
return output
}
/*
* Encode a string as utf-8
*/
function str2rstrUTF8 (input) {
return unescape(encodeURIComponent(input))
}
/*
* Take string arguments and return either raw or hex encoded strings
*/
function rawMD5 (s) {
return rstrMD5(str2rstrUTF8(s))
}
function hexMD5 (s) {
return rstr2hex(rawMD5(s))
}
function rawHMACMD5 (k, d) {
return rstrHMACMD5(str2rstrUTF8(k), str2rstrUTF8(d))
}
function hexHMACMD5 (k, d) {
return rstr2hex(rawHMACMD5(k, d))
}
function md5 (string, key, raw) {
if (!key) {
if (!raw) {
return hexMD5(string)
}
return rawMD5(string)
}
if (!raw) {
return hexHMACMD5(key, string)
}
return rawHMACMD5(key, string)
}
if (typeof define === 'function' && define.amd) {
define(function () {
return md5
})
} else if (typeof module === 'object' && module.exports) {
module.exports = md5
} else {
$.md5 = md5
}
})(this)
\ No newline at end of file
{
"ver": "1.0.5",
"uuid": "4a91d8ca-dc15-4d68-b5a1-141d4353425d",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
var MTA_CONFIG={app_id:"",event_id:"",api_base:"https://pingtas.qq.com/pingd",prefix:"_mta_",version:"1.3.5",stat_share_app:!1,stat_pull_down_fresh:!1,stat_reach_bottom:!1};function getNetworkType(a){wx.getNetworkType({success:function(b){a(b.networkType)}})}function getSystemInfo(){var a=wx.getSystemInfoSync();return{adt:encodeURIComponent(a.model),scl:a.pixelRatio,scr:a.windowWidth+"x"+a.windowHeight,lg:a.language,fl:a.version,jv:encodeURIComponent(a.system),tz:encodeURIComponent(a.platform)}}
function getUID(){try{return wx.getStorageSync(MTA_CONFIG.prefix+"auid")}catch(a){}}function setUID(){try{var a=getRandom();wx.setStorageSync(MTA_CONFIG.prefix+"auid",a);return a}catch(b){}}function getSID(){try{return wx.getStorageSync(MTA_CONFIG.prefix+"ssid")}catch(a){}}function setSID(){try{var a="s"+getRandom();wx.setStorageSync(MTA_CONFIG.prefix+"ssid",a);return a}catch(b){}}
function getRandom(a){for(var b=[0,1,2,3,4,5,6,7,8,9],c=10;1<c;c--){var d=Math.floor(10*Math.random()),e=b[d];b[d]=b[c-1];b[c-1]=e}for(c=d=0;5>c;c++)d=10*d+b[c];return(a||"")+(d+""+ +new Date)}function getPagePath(){try{var a=getCurrentPages(),b="/";0<a.length&&(b=a.pop().__route__);return b}catch(c){console.log("get current page path error:"+c)}}
function getMainInfo(){var a={dm:"wechat.apps.xx",url:getPagePath(),pvi:"",si:"",ty:0};a.pvi=function(){var b=getUID();b||(b=setUID(),a.ty=1);return b}();a.si=function(){var a=getSID();a||(a=setSID());return a}();return a}function getBasicInfo(){var a=getSystemInfo();getNetworkType(function(a){try{wx.setStorageSync(MTA_CONFIG.prefix+"ntdata",a)}catch(c){}});a.ct=wx.getStorageSync(MTA_CONFIG.prefix+"ntdata")||"4g";return a}
function getExtentInfo(){var a=MTA.Data.userInfo;var b=[],c;for(c in a)a.hasOwnProperty(c)&&b.push(c+"="+a[c]);a=b.join(";");return{r2:MTA_CONFIG.app_id,r4:"wx",ext:"v="+MTA_CONFIG.version+(null!==a&&""!==a?";ui="+encodeURIComponent(a):"")}}
var MTA={App:{init:function(a){"appID"in a&&(MTA_CONFIG.app_id=a.appID);"eventID"in a&&(MTA_CONFIG.event_id=a.eventID);"statShareApp"in a&&(MTA_CONFIG.stat_share_app=a.statShareApp);"statPullDownFresh"in a&&(MTA_CONFIG.stat_pull_down_fresh=a.statPullDownFresh);"statReachBottom"in a&&(MTA_CONFIG.stat_reach_bottom=a.statReachBottom);setSID();"lauchOpts"in a&&(MTA.Data.lanchInfo=a.lauchOpts,MTA.Data.lanchInfo.landing=1)}},Page:{init:function(){var a=getCurrentPages()[getCurrentPages().length-1];a.onShow&&
!function(){var b=a.onShow;a.onShow=function(){MTA.Page.stat();b.call(this,arguments)}}();MTA_CONFIG.stat_pull_down_fresh&&a.onPullDownRefresh&&!function(){var b=a.onPullDownRefresh;a.onPullDownRefresh=function(){MTA.Event.stat(MTA_CONFIG.prefix+"pulldownfresh",{url:a.__route__});b.call(this,arguments)}}();MTA_CONFIG.stat_reach_bottom&&a.onReachBottom&&!function(){var b=a.onReachBottom;a.onReachBottom=function(){MTA.Event.stat(MTA_CONFIG.prefix+"reachbottom",{url:a.__route__});b.call(this,arguments)}}();
MTA_CONFIG.stat_share_app&&a.onShareAppMessage&&!function(){var b=a.onShareAppMessage;a.onShareAppMessage=function(){MTA.Event.stat(MTA_CONFIG.prefix+"shareapp",{url:a.__route__});return b.call(this,arguments)}}()},stat:function(){if(""!=MTA_CONFIG.app_id){var a=[],b=getExtentInfo(),c=[getMainInfo(),b,getBasicInfo()];MTA.Data.lanchInfo&&(c.push({ht:MTA.Data.lanchInfo.scene,rdm:"/",rurl:MTA.Data.lanchInfo.path}),MTA.Data.lanchInfo.query&&MTA.Data.lanchInfo.query._mta_ref_id&&c.push({rarg:MTA.Data.lanchInfo.query._mta_ref_id}),
1==MTA.Data.lanchInfo.landing&&(b.ext+=";lp=1",MTA.Data.lanchInfo.landing=0));c.push({rand:+new Date});b=0;for(var d=c.length;b<d;b++)for(var e in c[b])c[b].hasOwnProperty(e)&&a.push(e+"="+("undefined"==typeof c[b][e]?"":c[b][e]));wx.request({url:MTA_CONFIG.api_base+"?"+a.join("&").toLowerCase()})}}},Event:{stat:function(a,b){if(""!=MTA_CONFIG.event_id){var c=[],d=getMainInfo(),e=getExtentInfo();d.dm="wxapps.click";d.url=a;e.r2=MTA_CONFIG.event_id;var f="undefined"===typeof b?{}:b;var k=[],g;for(g in f)f.hasOwnProperty(g)&&
k.push(encodeURIComponent(g)+"="+encodeURIComponent(f[g]));f=k.join(";");e.r5=f;f=0;d=[d,e,getBasicInfo(),{rand:+new Date}];for(e=d.length;f<e;f++)for(var h in d[f])d[f].hasOwnProperty(h)&&c.push(h+"="+("undefined"==typeof d[f][h]?"":d[f][h]));wx.request({url:MTA_CONFIG.api_base+"?"+c.join("&").toLowerCase()})}}},Data:{userInfo:null,lanchInfo:null}};module.exports=MTA;
\ No newline at end of file
{
"ver": "1.0.5",
"uuid": "bd4665a1-3060-42b8-9267-ffb43b8b839d",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
/**
1.安装apidoc,参考链接:
http://apidocjs.com
2.按照格式弄好后,执行命令
apidoc -i ./apiTest/assets/Sdk -o api/
在小程序后台添加合法域名:
https://game.llewan.com:1899
https://login.llewan.com:1799
https://log.llewan.com:1999
https://res.llewan.com:2099
https://glog.aldwx.com
*/
var md5 = require("md5");
var mta = require("mta");
var sdk_conf = require("sdk_conf");
var aldgame = require("ald-game");
var sdk = {
md5: md5,
mta: mta,
ip1: "https://login.llewan.com:1799",
ip2: "https://game.llewan.com:1899",
ip3: "https://log.llewan.com:1999",
ip4: "https://res.llewan.com:2099",
loginBg: "https://res.g.llewan.com/uploadfile/common/20180831/20180831173032_3279.png",
loginBt: "https://res.g.llewan.com/uploadfile/common/20180831/20180831180006_1583.png",
debug: false,//是否开启调试
login: '/Login/common',
Config: '/Config/common',
ConfigData: {
"config1": {},
"config2": {},
"config3": {},
"config4": {},
},
Share: "/Share/common",
ShareList: [],
Logcommon: "/Log/common",
BannerAd: null,
VideoAd: null,
//.即将废弃,请不要操作此变量。
userid: 0,
/**
* @apiGroup A
* @apiName init
* @api {初始化sdk} 使用sdk前,必须先初始化一次才能使用 init(初始化sdk)
*
* @apiParam {Boolean} [debug=false] 是否开启调试
* @apiParam {int} [userid] 用户的id(兼容旧游戏,新游戏废弃)
*
* @apiSuccessExample {json} 示例:
* //.初始化游戏
* sdk.init({
* debug: true, //.是否开启调试
* userid: 56032607 //.用户的id(兼容旧游戏,新游戏废弃)
* }, (res)=>{
* console.log('sdk初始化结果:', res)
* })
*/
init(args, callback){
var self = this;
if(args.debug){
this.debug = args.debug;
}
if(args.userid){
this.userid = args.userid;
}
this.checkUpdate();
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
//1.初始化后台配置信息
this.Post(this.ip2 + this.Config, {}, function (d) {
if (d && d.c == 1) {
self.ConfigData = d.d;
//2.初始化分享信息
self.Post(self.ip2 + self.Share, {}, function (d2) {
// console.log("初始化分享信息:",d2)
if (d2 && d2.c == 1) {
self.ShareList = d2.d;
}else{
console.log("初始化分享信息失败:",d2)
}
callback(true);
});
}else{
if(self.debug){
console.log("后台配置信息初始化失败,再次初始化:",d)
}
self.init(args, callback);
}
});
if(this.getUser()){
this.userid = this.getUser().uid;
}
if(this.userid){
//2.统计:分享信息 测试: uid=56032607&share_id=22&share_uid=56032607
var option = wx.getLaunchOptionsSync();
// console.log("==option==", option)
if(option.query.share_id && option.query.uid){
option.query.share_uid = option.query.uid;
option.query.uid = this.userid;
// console.log('==3统计信息==',option)
this.Post(this.ip3 + this.Logcommon, { log_type: "ShareEnter", data: JSON.stringify(option) }, function (d) {
// console.log("==3统计信息结果==", d)
});
}
wx.onShow((option)=>{
// console.log(option)
if(option.query.uid){
option.query.share_uid = option.query.uid;
option.query.uid = self.userid;
// console.log('==4统计信息==',option)
self.Post(self.ip3 + self.Logcommon, { log_type: "ShareEnter", data: JSON.stringify(option) }, function (d) {
// console.log("==4统计信息结果==", d)
});
}
})
//5.统计:每次打开小游戏调用
wx.getSystemInfoSync({
success(res){
var loginData = res;
loginData.uid = self.userid;
loginData.share_uid = option.query.share_uid;
loginData.scene = option.scene;
loginData.source_id = option.query.source_id;
loginData.source_id2 = option.query.source_id2;
wx.getNetworkType({
success(res2){
loginData.network_type = res2.networkType;
// console.log("======loginData=======", loginData)
self.Get(self.ip3 + self.Logcommon, { log_type: "LoginData", data: JSON.stringify(loginData) }, function (d) {
// console.log("==5.统计:每次打开小游戏调用==", d)
});
}
})
}
})
}
}
},
//.根据权重随机获取指定type类型的分享信息。(没有this.ShareList数据不能调用)
getShareByWeight(type){
if(this.ShareList.length > 0){
//1.获取某种type的集合
var tArray = [];
for (var i = 0; i < this.ShareList.length; i++) {
if (type == this.ShareList[i].type) {
this.ShareList[i].weight = parseInt(this.ShareList[i].weight);
tArray.push(this.ShareList[i]);
}
}
//2.根据权重配比:从i集合(权重越大占比越多)中随机获取。
var iArray = [];
for (var i = 0; i < tArray.length; i++) {
for (var j = 0; j < tArray[i].weight; j++) {
iArray.push(i);
}
}
var i = iArray[parseInt(Math.random() * iArray.length)];
//3.结果处理:正则替换昵称
var item = tArray[i];
if(item.title.indexOf("&nickName") != -1){
item.title = item.title.replace(/&nickName/g, this.getUser().nickName);
}
return JSON.parse(JSON.stringify(item));
}else{
return null;
}
},
/**
* @apiGroup C
* @apiName onShareAppMessage
* @api {分享} 注册微信右上角分享 onShareAppMessage(分享)
* @apiParam {int} type=0 后台自定义的分享类型;例如:0:右上角分享、1:普通分享 2:分享加金币
* @apiParam {String} [title] 转发标题
* @apiParam {String} [imageUrl] 转发显示图片的链接
* @apiParam {String} [query] 必须是 key1=val1&key2=val2 的格式。
* @apiParam {callback} [success] 成功回调
* @apiParam {callback} [fail] 失败回调
*
* @apiSuccessExample {json} 示例:
* sdk.onShareAppMessage({type: 0, query: "uid=520" });
*/
onShareAppMessage(obj){
var self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
//.微信右上角分享
///|wx.showShareMenu({withShareTicket:true})
wx.shareAppMessage(function(res){
//.默认0:右上角分享
var tpye = 0;
if(obj.type){
tpye = obj.type;
}
var shareInfo = self.getShareByWeight(tpye)
if(obj.title){
shareInfo.title = obj.title;
}
if(obj.imageUrl){
shareInfo.imageUrl = obj.imageUrl;
}
if(shareInfo.query){
shareInfo.query += obj.query + "&share_id="+shareInfo.sysid + "&uid="+self.userid;
}else{
if(obj.query){
shareInfo.query = "share_id="+shareInfo.sysid+"&uid="+self.userid +"&" + obj.query;
}else{
shareInfo.query = "share_id="+shareInfo.sysid + "&uid="+self.userid;
}
}
if(obj.success){
shareInfo.success = obj.success;
}
if(obj.fail){
shareInfo.fail = obj.fail;
}
//.分享统计 测试: uid=11&share_id=22
var option = {'uid': sdk.userid, 'share_id': shareInfo.sysid };
// console.log('==1统计信息==', { log_type: "ShareClick", data: option })
self.Get(self.ip3 + self.Logcommon, { log_type: "ShareClick", data: JSON.stringify(option) }, function (d) {
// console.log("==1统计信息结果==", d)
});
return shareInfo;
})
}
},
/**
* @apiGroup C
* @apiName shareAppMessage
* @api {分享} 主动拉起微信分享 shareAppMessage(分享)
* @apiParam {int} type=1 后台自定义的分享类型;例如:0:右上角分享、1:普通分享 2:分享加金币
* @apiParam {String} [title] 转发标题
* @apiParam {String} [imageUrl] 转发显示图片的链接
* @apiParam {String} [query] 必须是 key1=val1&key2=val2 的格式。
* @apiParam {callback} [success] 成功回调
* @apiParam {callback} [fail] 失败回调
*
* @apiSuccessExample {json} 示例:
* sdk.shareAppMessage({type: 1, query: "uid=520" });
*/
shareAppMessage(obj){
var self = this;
//.默认1:普通分享
var tpye = 1;
if(obj.type){
tpye = obj.type;
}
var shareInfo = this.getShareByWeight(tpye);
if(obj.title){
shareInfo.title = obj.title;
}
if(obj.imageUrl){
shareInfo.imageUrl = obj.imageUrl;
}
if(shareInfo.query){
shareInfo.query += obj.query + "&share_id="+shareInfo.sysid + "&uid="+self.userid;
}else{
if(obj.query){
shareInfo.query = "share_id="+shareInfo.sysid+"&uid="+self.userid +"&" + obj.query;
}else{
shareInfo.query = "share_id="+shareInfo.sysid + "&uid="+self.userid;
}
}
if(obj.success){
shareInfo.success = obj.success;
}
if(obj.fail){
shareInfo.fail = obj.fail;
}
console.log("====111======", shareInfo);
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
wx.shareAppMessage(shareInfo);
//.分享统计 测试: uid=11&share_id=22
var option = {'uid': sdk.userid, 'share_id': shareInfo.sysid };
// console.log('==2统计信息==', { log_type: "ShareClick", data: option })
self.Get(self.ip3 + self.Logcommon, { log_type: "ShareClick", data: JSON.stringify(option) }, function (d) {
// console.log("==2统计信息结果==", d)
});
}
},
/**
* @apiIgnore
* @apiGroup B
* @apiName initmta
* @api {初始化腾讯统计sdk} 参考链接http://mta.qq.com/wechat_mini/manage/ctr_sdk_help?app_id=500625714 initmta(腾讯统计)
* @apiParam {Object} args 参数
*
* @apiSuccessExample {json} 示例:
* //.简单
* mta.App.init({
* "appID":"500618042",
* "eventID":"500618044"
* });
* //.高级
* mta.App.init({
* "appID":"500618042",
* "eventID":"500618044", // 高级功能-自定义事件统计ID,配置开通后在初始化处填写
* "lauchOpts":options, //渠道分析,需在onLaunch方法传入options,如onLaunch:function(options){...}
* "statPullDownFresh":true, // 使用分析-下拉刷新次数/人数,必须先开通自定义事件,并配置了合法的eventID
* "statShareApp":true, // 使用分析-分享次数/人数,必须先开通自定义事件,并配置了合法的eventID
* "statReachBottom":true // 使用分析-页面触底次数/人数,必须先开通自定义事件,并配置了合法的eventID
* });
*/
initmta(args){
mta.App.init(args);
// 功能组件
// App id: 500625714
// App Secret key: 9b0fd6393ca10f5eebe0d1c659a460ab
},
/**
* @apiIgnore
* @apiGroup B
* @apiName setmta
* @api {腾讯统计埋点} 统计埋点 setmta
* @apiParam {String} name 腾讯后台查询
* @apiParam {String} value 腾讯后台查询
*
* @apiSuccessExample {json} 示例:
* sdk.setmta("click","p003")
*/
setmta(name, value){
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
mta.Event.stat(name, { value: 'true' })
}
},
/**
* @apiGroup B
* @apiName setAld
* @api {阿拉丁埋点} 统计埋点(使用前请到阿拉丁注册游戏,并配置sdk/ald-game-conf.js) setAld(阿拉丁埋点)
* @apiParam {String} type 描述用户的动作名称,不超过255个字符,不支持数字,英文,中文,"-"、"_"、"+",以外的字符格式
* @apiParam {String} key 动作的参数,不超过255个字符,不支持数字,英文,中文,"-"、"_"、"+",以外的字符格式
* @apiParam {String} value 动作的参数值,不超过255个字符,不支持数字,英文,中文,“-“、”_”、"+",以外的字符格式
*
* @apiSuccessExample {json} 示例:
* //使用前,在开发者设置中添加 request合法域名https://glog.aldwx.com
* //统计类型(点击), 统计位置(开始游戏按钮), 统计参数(点了1次)
* sdk.setAld("click", "playButton", "1")
*/
setAld(type, key, value){
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
// wx.aldSendEvent('事件名称',{'参数key' : '参数value'})、
wx.aldSendEvent(v1, { v2 : v3 })
}
},
/**
* @apiGroup C
* @apiName Get
* @api {Get} 发起网络请求 Get(发起Get请求)
*
* @apiParam {String} url 请求地址
* @apiParam {Object} reqData 请求参数
* @apiParam {Object} callback 不存在返回null
* @apiSuccessExample {json} 示例:
* sdk.Get("https://xxx.xxx", { user_id: user_id }, function (d) {
* console.log(d)
* });
*/
Get(url, reqData, callback) {
var self = this;
reqData.game = sdk_conf.game;
reqData.version = sdk_conf.version;
reqData.dev_platform = sdk_conf.dev_platform;
var ts = new Date().getTime();
reqData.ts = ts;
var token = "";
if(this.getUser())
{
token = this.getUser().token;
}
var options = wx.getLaunchOptionsSync();
var source_id = options.query.source_id;
//数据验证签名。规则为:MD5(ts.substr(9,4)+game.substr(0,2)+version.substr(0,1)+key),时间戳后4位、data前3位、key(服务端提供)然后进行MD5加密
reqData.sign = md5(ts.toString().substr(9,4)+sdk_conf.game.substr(0,2)+sdk_conf.version.substr(0,1)+ '$5dfjr$%dsadsfdsii');
url += "?";
for (var item in reqData) {
url += item + "=" + reqData[item] + "&";
}
url += "token="+token+"&";
url += "source_id="+source_id+"&";
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 400) {
var response = xhr.responseText;
if (response) {
var responseJson = JSON.parse(response);
callback(responseJson);
} else {
if(self.debug){
console.log("返回数据不存在",url)
}
callback(null);
}
} else {
if(self.debug){
console.log("请求失败",url)
}
callback(null);
}
}
};
xhr.open("GET", url, true);
xhr.send();
},
/**
* @apiGroup C
* @apiName Post
* @api {Post} 发起网络请求 Post(发起Post请求)
*
* @apiParam {String} url 请求地址
* @apiParam {Object} reqData 请求参数
* @apiParam {Object} callback 不存在返回null
* @apiSuccessExample {json} 示例:
* sdk.Post(sdk.ip + sdk.common, { user_id: user_id }, function (d) {
* console.log(d)
* });
*/
Post: function (url, reqData, callback) {
var self = this;
reqData.game = sdk_conf.game;
reqData.version = sdk_conf.version;
reqData.dev_platform = sdk_conf.dev_platform;
var ts = new Date().getTime();
var token = "";
if(this.getUser())
{
token = this.getUser().token;
}
var options = wx.getLaunchOptionsSync();
var source_id = options.query.source_id;
reqData.ts = ts;
reqData.sign = md5(ts.toString().substr(9,4)+sdk_conf.game.substr(0,2)+sdk_conf.version.substr(0,1)+ '$5dfjr$%dsadsfdsii');
//1.拼接请求参数
var param = "";
for (var item in reqData) {
param += item + "=" + reqData[item] + "&";
}
param +="token="+token+ "&";
param += "source_id="+source_id+"&";
//2.发起请求
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 400) {
var response = xhr.responseText;
// console.log(response)
if (response) {
var responseJson = JSON.parse(response);
callback(responseJson);
} else {
if(self.debug){
console.log("返回数据不存在")
}
callback(null);
}
} else {
if(self.debug){
console.log("请求失败",xhr)
}
callback(null);
}
}
};
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(param);//reqData为字符串形式: "key=value"
},
/**
* @apiGroup C
* @apiName checkUpdate
* @api {检测版本更新} 微信小游戏(冷启动的时候会检查,如果有更新则会重启小游戏进行更新) checkUpdate(版本更新)
*
* @apiSuccessExample {json} 示例:
* sdk.checkUpdate();
*/
checkUpdate() {
var self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME && typeof wx.getUpdateManager === 'function') {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
if(self.debug){
console.log("请求完新版本信息的回调", res.hasUpdate)
}
})
updateManager.onUpdateReady(function () {
if(self.debug){
console.log("新的版本已经下载好,调用 applyUpdate 应用新版本并重启")
}
updateManager.applyUpdate()
})
updateManager.onUpdateFailed(function () {
if(self.debug){
console.log("新的版本下载失败")
}
})
}
},
/**
* @apiGroup C
* @apiName getConfig1
* @api {运营配置} 游戏后台配置信息,运营人员使用的通用配置开关 getConfig1(运营配置)
* @apiParam {Object} callback 不存在返回null
*
* @apiSuccessExample {json} 示例:
* var d = sdk.getConfig1();
*/
getConfig1(){
return JSON.parse(this.ConfigData.config1);
},
/**
* @apiGroup C
* @apiName getConfig2
* @api {程序配置} 游戏后台配置信息,程序员使用的游戏数据开关,可随便自定义数据:例如复活次数等 getConfig2(程序配置)
* @apiParam {Object} callback 不存在返回null
*
* @apiSuccessExample {json} 示例:
* var d = sdk.getConfig2();
*/
getConfig2(){
return JSON.parse(this.ConfigData.config2);
},
/**
* @apiGroup C
* @apiName getConfig3
* @api {运营配置} 游戏后台配置信息,运营人员使用的通用配置开关 相关按钮根据时间来配置以及跳转方式按钮属性getConfig3(运营配置)
* @apiParam {Object} callback 不存在返回null
*
* @apiSuccessExample {json} 示例:
* var d = sdk.getConfig3();
*/
getConfig3(){
return JSON.parse(this.ConfigData.config3);
},
/**
* @apiGroup C
* @apiName getConfig4
* @api {技术程序控制} 游戏服务端控制一些需要服务端判断的比如:ip地区配置,getConfig4(技术程序)
* @apiParam {Object} callback 不存在返回null
*
* @apiSuccessExample {json} 示例:
* var d = sdk.getConfig4();
*/
getConfig4(){
return JSON.parse(this.ConfigData.config4);
},
/**
* @apiGroup C
* @apiName createImage
* @api {显示网络图片} 微信小游戏加载图片 createImage(显示图片)
* @apiParam {cc.Sprite} sprite 显示图片的Sprite
* @apiParam {String} url 需要加载的图片地址
*
* @apiSuccessExample {json} 示例:
* var data = sdk.createImage(advs);
*/
createImage(sprite, url) {
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
let image = wx.createImage();
image.onload = function () {
let texture = new cc.Texture2D();
texture.initWithElement(image);
texture.handleLoadedTexture();
sprite.spriteFrame = new cc.SpriteFrame(texture);
};
image.src = url;
}
},
/**
* @apiGroup C
* @apiName getUser
* @api {获取本地用户信息} 获取本地用户信息(登录成功后,会在本地存储用户信息) getUser(获取用户信息)
*
* @apiSuccessExample {json} 示例:
* //.不存在返回null
* var user = sdk.getUser();
*/
getUser(){
var userinfo = this.getItem('userinfo');
if(userinfo){
return JSON.parse(userinfo);
}else{
return null;
}
},
/**
* @apiGroup C
* @apiName setItem
* @api {set} 数据存储 setItem(存)
* @apiParam {String} key 键
* @apiParam {String} value 值
*
* @apiSuccessExample {json} 示例:
* sdk.setItem("nick","hello")
*/
setItem(key, value){
cc.sys.localStorage.setItem(key, value);
},
/**
* @apiGroup C
* @apiName getItem
* @api {数据存储} 数据存储 getItem(取)
* @apiParam {String} key 键
* @apiParam {String} value 值
*
* @apiSuccessExample {json} 示例:
* var nick = sdk.getItem("nick")
*/
getItem(key){
return cc.sys.localStorage.getItem(key);
},
/**
* @apiGroup C
* @apiName onMessage
* @api {主域监听子域发送的消息} 主域监听子域发送的消息 onMessage(监听消息)
* @apiParam {callback} callback 回调函数
*
* @apiSuccessExample {json} 示例:
* sdk.onMessage((d)=>{
* console.log(d)
* })
*/
onMessage(callback){
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
wx.onMessage(function(d){
// if(d.message == "common_back"){//.子域: 返回子域首页
// cc.director.loadScene("common_children")
// }
callback(d)
});
}
},
/**
* @apiGroup C
* @apiName postMessage
* @api {主域向子域发送消息} 主域向子域发送消息 postMessage(发送消息)
* @apiParam {String} msg 发送给子域的消息
*
* @apiSuccessExample {json} 示例:
* sdk.postMessage("hello")
*/
postMessage(msg){
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
wx.postMessage({ message: msg });
}
},
//.主域上报数据: 对用户托管数据进行写数据操作,允许同时写多组 KV 数据。
setUserCloudStorage(kvDataList, callback){
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
wx.setUserCloudStorage({
KVDataList: kvDataList,
success(res){
callback(res)
},
fail(res){
callback(res)
}
})
}
},
//.获取当前用户托管数据当中对应 key 的数据。该接口只可在开放数据域下使用
getUserCloudStorage(keyList, callback){
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
wx.getUserCloudStorage({
keyList: keyList,
success(res){
callback(res)
},
fail(res){
callback(res)
}
})
}
},
//.在小游戏是通过群分享卡片打开的情况下,可以通过调用该接口获取群同玩成员的游戏数据。该接口只可在开放数据域下使用。
getGroupCloudStorage(shareTicket, keyList, callback){
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
wx.getGroupCloudStorage({
shareTicket: shareTicket,
keyList: keyList,
success(res){
callback(res)
},
fail(res){
callback(res)
}
})
}
},
//.拉取当前用户所有同玩好友的托管数据。该接口只可在开放数据域下使用
getFriendCloudStorage(keyList, callback){
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
wx.getFriendCloudStorage({
keyList: keyList,
success(res){
callback(res)
},
fail(res){
callback(res)
}
})
}
},
/**
* @apiGroup C
* @apiName sortList
* @api {对子域数据进行排序} 对子域数据进行排序 sortList(子域排序)
* @apiParam {String} ListData 要排序的微信子域数据
* @apiParam {String} field 排序字段
* @apiParam {String} order 正序:true ; 倒序:false
*
* @apiSuccessExample {json} 示例:
* wx.getFriendCloudStorage({
* keyList: ["score"],
* success(res){
* var ListData = sdk.sortList(res.data, 'score', true));
* console.log("=排序后的数据=", ListData);
* },
* fail(){
* console.log(res)
* }
*})
*/
sortList(ListData, field, order){
ListData.sort(function(a,b){
var AMaxScore = 0;
var KVDataList = a.KVDataList;
for(var i=0; i<KVDataList.length; i++){
if(KVDataList[i].key == field){
AMaxScore = KVDataList[i].value;
}
}
var BMaxScore = 0;
KVDataList = b.KVDataList;
for(var i=0; i<KVDataList.length; i++){
if(KVDataList[i].key == field){
BMaxScore = KVDataList[i].value;
}
}
if(order){
return parseInt(AMaxScore) - parseInt(BMaxScore);
}else{
return parseInt(BMaxScore) - parseInt(AMaxScore);
}
});
return ListData;
},
/**
* @apiIgnore
* @apiGroup C
* @apiName getMyRank3
* @api {排名与我相邻的3位玩家信息} 排名与我相邻的3位玩家信息 getMyRank3(Top3)
* @apiParam {String} ListData 要排序的微信子域数据
* @apiParam {String} me 我的子域信息
*
* @apiSuccessExample {json} 示例:
* wx.getUserInfo({
* openIdList: ['selfOpenId'],
* lang: 'zh_CN',
* success(res){
* //.Top3
* var dList = sdk.getMyRank3(dataList,res.data[0]);
* console.log(dList)
* },
* fail(error) {
* console.log(error)
* }
* })
*
*
*/
getMyRank3(ListData,me){
var dataList = [];
for(var i=0; i<ListData.length; i++){
if(ListData.length <= 3){
//.只有3个人或以下
if(ListData[i].avatarUrl == me.avatarUrl && ListData[i].nickname == me.nickName){
ListData[i].isSelf = true;//.标记自己
}
dataList = ListData;
for(var i=0; i<dataList.length; i++){
dataList[i].rank = i;
}
}else{
if(ListData[i].avatarUrl == me.avatarUrl && ListData[i].nickname == me.nickName){
ListData[i].isSelf = true;//.标记自己
if(i == ListData.length-1){
//.自己分数最低
ListData[i].rank = i;
ListData[i-1].rank = i-1;
ListData[i-2].rank = i-2;
dataList.push(ListData[i-2])
dataList.push(ListData[i-1])
dataList.push(ListData[i])
}else if(i==0){
//.自己分数最高
ListData[i].rank = i;
ListData[i+1].rank = i+1;
ListData[i+2].rank = i+2;
dataList.push(ListData[i])
dataList.push(ListData[i+1])
dataList.push(ListData[i+2])
}else{
//.居中
ListData[i-1].rank = i-1;
ListData[i].rank = i;
ListData[i+1].rank = i+1;
dataList.push(ListData[i-1])
dataList.push(ListData[i])
dataList.push(ListData[i+1])
}
break;
}
}
}
return dataList;
},
/**
* @apiGroup C
* @apiName wxLogin
* @api {微信登录} 微信登录 wxLogin(登录)
*
* @apiSuccessExample {json} 示例:
* // 2.登录页:获取用户信息
* var user = sdk.getUser();
* if(user){
* console.log("用户信息:", user)
* }else{
* //.调用sdk登录
* sdk.wxLogin((d)=>{
* console.log("用户信息:", d)
* // 登录成功:返回用户信息;
* // 登录失败:返回false
* });
* }
*
*/
WxLogin(callback){
var self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
var options = wx.getLaunchOptionsSync();
var referee_id = options.query.uid; //.推荐人id
var source_id = options.query.source_id; //.用户来源id
var source_id2 = options.query.source_id2; //.用户来源子id
var share_id = options.query.share_id; //.分享素材ID
wx.login({
success(res2){
var reqData = {
code: res2.code,
referee_id: referee_id,
source_id: source_id,
source_id2: source_id2,
share_id: share_id
}
// console.log('==登录参数==', reqData)
self.Post(self.ip1 + self.login, reqData, function(data){
// console.log('==登录结果==', data)
if(data.c == 1){
self.setItem('userinfo', JSON.stringify(data.d));
callback(data.d);
}else{
// console.log('==登录接口请求失败==', data)
wx.showToast({title: '登录失败请重试'});
}
});
},
fail(){
wx.showToast({title: '登录失败请重试'});
callback(false)
},
})
}
},
/**
* @apiGroup C
* @apiName wxAuth
* @api {微信授权} 微信登录 wxAuth(授权)
*
* @apiSuccessExample {json} 示例:
* // 2.登录页:获取用户信息
* var user = sdk.getUser();
* if(user){
* console.log("用户信息:", user)
* }else{
* //.调用sdk登录
* sdk.wxAuth((d)=>{
* console.log("用户信息:", d)
* // 登录成功:返回用户信息;
* // 登录失败:返回false
* });
* }
*
*/
WxAuthLogin(callback){
var self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
var options = wx.getLaunchOptionsSync();
var referee_id = options.query.uid; //.推荐人id
var source_id = options.query.source_id; //.用户来源id
var source_id2 = options.query.source_id2; //.用户来源子id
var share_id = options.query.share_id; //.分享素材ID
var userinfo = this.getUser();
//.登录遮罩背景
var maskNode = new cc.Node('Sprite');
maskNode.parent = cc.director.getScene().getChildByName('Canvas');
maskNode.addComponent(cc.BlockInputEvents)
var sp = maskNode.addComponent(cc.Sprite);
maskNode.opacity = 178;
maskNode.color = new cc.Color(25,88,95,255);
sp.sizeMode = cc.Sprite.SizeMode.CUSTOM;
self.createImage(sp, self.loginBg);
maskNode.width = cc.view.getVisibleSize().width;
maskNode.height = cc.view.getVisibleSize().height;
// console.log(maskNode.width, maskNode.height)
//.微信登录按钮
if(self.button){
self.button.show();
}else{
wx.getSystemInfo({
success(res){
var width = 507/2;
var height = 464/2;
self.button = wx.createUserInfoButton({
type: 'image',
image: self.loginBt,
style: { width: width, height: height, left: res.screenWidth/2-width/2, top: res.screenHeight/2-height/2 }
})
self.button.onTap((res1) => {
// 处理用户拒绝授权的情况
// if (res1.errMsg.indexOf('auth deny') > -1 || res1.errMsg.indexOf('auth denied') > -1 ) {
// wx.showToast();
// }
wx.showToast({title: '登录中...',icon:'loading',duration: 8});
wx.getSetting({
success(auths){
if(auths.authSetting["scope.userInfo"]){
self.setItem("wxauth",1);
console.log('===已经授权===');
wx.login({
success(res2){
var reqData = {
code: res2.code,
rawData: res1.rawData,
iv: res1.iv,
encryptedData: res1.encryptedData,
signature: res1.signature,
referee_id: referee_id,
source_id: source_id,
source_id2: source_id2,
share_id: share_id
}
// console.log('==登录参数==', reqData)
self.Post(self.ip1 + self.login, reqData, function(data){
// console.log('==登录结果==', data)
if(data.c == 1){
self.setItem('userinfo', JSON.stringify(data.d));
wx.hideToast();
maskNode.destroy();
self.button.hide();
//.登录成功,重新初始化
self.userid = data.d.uid;
self.init({},(d)=>{})
callback(data.d);
}else{
// console.log('==登录接口请求失败==', data)
wx.showToast({title: '登录失败请重试'});
}
});
},
fail(){
wx.showToast({title: '登录失败请重试'});
callback(false)
},
})
}else{
callback(false)
}
}
})
})
self.button.show()
}
})
}
}
},
/**
* @apiGroup C
* @apiName WeChatLogin
* @api {微信登录} 微信登录 WeChatLogin(登录)
*
* @apiSuccessExample {json} 示例:
* // 2.登录页:获取用户信息
* var user = sdk.getUser();
* if(user){
* console.log("用户信息:", user)
* }else{
* //.调用sdk登录
* sdk.WeChatLogin((d)=>{
* console.log("用户信息:", d)
* // 登录成功:返回用户信息;
* // 登录失败:返回false
* });
* }
*
*/
WeChatLogin(callback){
var self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
var userinfo = this.getUser();
var wxauth = this.getItem("wxauth"); //记录微信是否授权
if(userinfo&&wxauth){
console.log("直接进入游戏");
//用户信息获取到并且授权了
callback(userinfo)
}else if(userinfo&&!wxauth)
{
//用户信息存在但是没有授权,就应该去授权后调用服务端member/update用户信息
this.WxAuthLogin((d) => {
console.log("授权1");
callback(d);
});
}else if(!userinfo&&wxauth)
{
//用户信息没有但是有授权,就应该去登陆并且去授权后调用服务端member/update用户信息
this.WxAuthLogin((d) => {
console.log("授权2");
callback(d);
});
}
else{
//没有用户信息,也没有授权,就应该去登陆并且去授权后调用服务端member/update用户信息
this.WxLogin((d) => {
console.log("登陆");
});
this.WxAuthLogin((d) => {
console.log("授权3");
callback(d);
});
}
}
},
// WeChatLogin(callback){
// var self = this;
// if (cc.sys.platform === cc.sys.WECHAT_GAME) {
// var options = wx.getLaunchOptionsSync();
// var referee_id = options.query.uid; //.推荐人id
// var source_id = options.query.source_id; //.用户来源id
// var source_id2 = options.query.source_id2; //.用户来源子id
// var share_id = options.query.share_id; //.分享素材ID
// var userinfo = this.getUser();
// var wxauth = this.getItem("wxauth"); //记录微信是否授权
// if(userinfo&&wxauth){
// //用户信息获取到并且授权了
// callback(userinfo)
// }else if(userinfo&&!wxauth)
// {
// //用户信息存在但是没有授权,就应该去授权后调用服务端member/update用户信息
// }else if(!userinfo&&wxauth)
// {
// //用户信息没有但是有授权,就应该去登陆并且去授权后调用服务端member/update用户信息
// }
// else{
// //没有用户信息,也没有授权,就应该去登陆并且去授权后调用服务端member/update用户信息
// //.登录遮罩背景
// var maskNode = new cc.Node('Sprite');
// maskNode.parent = cc.director.getScene().getChildByName('Canvas');
// maskNode.addComponent(cc.BlockInputEvents)
// var sp = maskNode.addComponent(cc.Sprite);
// maskNode.opacity = 178;
// maskNode.color = new cc.Color(25,88,95,255);
// sp.sizeMode = cc.Sprite.SizeMode.CUSTOM;
// self.createImage(sp, self.loginBg);
// maskNode.width = cc.view.getVisibleSize().width;
// maskNode.height = cc.view.getVisibleSize().height;
// // console.log(maskNode.width, maskNode.height)
// //.微信登录按钮
// if(self.button){
// self.button.show();
// }else{
// wx.getSystemInfo({
// success(res){
// var width = 507/2;
// var height = 464/2;
// self.button = wx.createUserInfoButton({
// type: 'image',
// image: self.loginBt,
// style: { width: width, height: height, left: res.screenWidth/2-width/2, top: res.screenHeight/2-height/2 }
// })
// self.button.onTap((res1) => {
// // 处理用户拒绝授权的情况
// // if (res1.errMsg.indexOf('auth deny') > -1 || res1.errMsg.indexOf('auth denied') > -1 ) {
// // wx.showToast();
// // }
// wx.showToast({title: '登录中...',icon:'loading',duration: 8});
// wx.getSetting({
// success(auths){
// if(auths.authSetting["scope.userInfo"]){
// this.setItem("wxauth",1);
// console.log('===已经授权===');
// wx.login({
// success(res2){
// var reqData = {
// code: res2.code,
// rawData: res1.rawData,
// iv: res1.iv,
// encryptedData: res1.encryptedData,
// signature: res1.signature,
// referee_id: referee_id,
// source_id: source_id,
// source_id2: source_id2,
// share_id: share_id
// }
// // console.log('==登录参数==', reqData)
// self.Post(self.ip1 + self.login, reqData, function(data){
// // console.log('==登录结果==', data)
// if(data.c == 1){
// self.setItem('userinfo', JSON.stringify(data.d));
// wx.hideToast();
// maskNode.destroy();
// self.button.hide();
// //.登录成功,重新初始化
// self.userid = data.d.uid;
// self.init({},(d)=>{})
// callback(data.d);
// }else{
// // console.log('==登录接口请求失败==', data)
// wx.showToast({title: '登录失败请重试'});
// }
// });
// },
// fail(){
// wx.showToast({title: '登录失败请重试'});
// callback(false)
// },
// })
// }else{
// callback(false)
// }
// }
// })
// })
// self.button.show()
// }
// })
// }
// }
// }
// },
/**
* @apiGroup C
* @apiName createBannerAd
* @api {微信登录} 创建banner广告组件 createBannerAd(广告)
* @apiParam {String} adUnitId 广告单元id
* @apiParam {String} style banner 广告组件的样式
*
* @apiSuccessExample {json} 示例:
* //.参考文档:https://developers.weixin.qq.com/minigame/dev/document/ad/wx.createBannerAd.html
* //var bannerAd = sdk.createBannerAd({
* // style:{
* // left: 0,
* // top: 0,
* // width: 100,
* // height: 200
* // }
* //});
*
* //.极简版(默认底部Banner)
* var bannerAd = sdk.createBannerAd({});
* bannerAd.show()
*
*/
createBannerAd(obj){
var self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
if(this.BannerAd){
return this.BannerAd;
}else{
if(!obj.style){
obj.style = {};
var phone = wx.getSystemInfoSync();
this.w = phone.screenWidth / 2;
this.h = phone.screenHeight;
obj.style.left = 0;
obj.style.top = 0;
obj.style.width = 300;
}
this.BannerAd = wx.createBannerAd({
adUnitId: sdk_conf.bannerAdUnitId,
style: obj.style,
})
this.BannerAd.onResize(function(res){
console.log("BannerAd广告缩放事件:", res)
self.BannerAd.style.left = self.w - self.BannerAd.style.realWidth/2+0.1;
self.BannerAd.style.top = self.h - self.BannerAd.style.realHeight+0.1;
});
this.BannerAd.onLoad(function(res){
console.log("BannerAd广告加载事件:", res)
});
this.BannerAd.onError(function(res){
console.log("BannerAd广告错误事件:", res)
});
return this.BannerAd;
}
}
},
/**
* @apiGroup C
* @apiName createRewardedVideoAd
* @api {微信登录} 创建banner广告组件 createRewardedVideoAd(广告)
* @apiParam {String} adUnitId 广告单元id
*
* @apiSuccessExample {json} 示例:
* //.参考文档:https://developers.weixin.qq.com/minigame/dev/document/ad/wx.createRewardedVideoAd.html
* var videoAd = sdk.createRewardedVideoAd();
* videoAd.load().then(() => videoAd.show());
*
*/
createRewardedVideoAd(){
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
if(this.VideoAd){
return this.VideoAd;
}else{
this.VideoAd = wx.createRewardedVideoAd({ adUnitId: sdk_conf.videoAdUnitId })
this.VideoAd.onLoad(function(res){
console.log("VideoAd广告加载事件:", res)
});
this.VideoAd.onError(function(res){
console.log("VideoAd广告错误事件:", res)
});
return this.VideoAd;
}
}
},
/**
* @apiGroup C
* @apiName Screenshot
* @api {微信小游戏截图保存} 微信小游戏截图保存 Screenshot(截图)
*
* @apiSuccessExample {json} 示例:
* //.摄像机组件、回调
* sdk.Screenshot((d)=>{
* if(d){
* console.log("图片保存成功:", d)
* }else{
* console.log("图片保存失败:", d)
* }
* })
*
*/
Screenshot(callback){
var self = this;
//1.判断是否授权
wx.getSetting({
success(res){
// console.log("授权状态", res.authSetting['scope.writePhotosAlbum'])
if(res.authSetting['scope.writePhotosAlbum']){
self.capture(callback);
}else{
// console.log("未授权", res)
wx.authorize({
scope: 'scope.writePhotosAlbum',
success(res2){
// console.log("success res2",res2)
self.Screenshot(callback);
},
fail(res2){
// console.log("重新授权")
wx.showModal({
title: '提示',
content: '请开启保存到相册功能',
showCancel: false,
success(){
wx.openSetting({
success(res3){
// console.log("===重新授权===", res3)
if(res3.authSetting['scope.writePhotosAlbum']){
self.Screenshot(callback);
}else{
wx.showToast({ title: "授权失败" })
callback(null)
}
}
})
}
})
}
})
}
},
fail(){
callback(null)
}
})
},
capture (callback) {
if(cc.ENGINE_VERSION < "2.0.0"){
//1.9.3旧版本截图
var canvas = cc.game.canvas;
var width = cc.winSize.width;
var height = cc.winSize.height;
canvas.toTempFilePath({
x: 0,
y: 0,
width: width,
height: height,
destWidth: width,
destHeight: height,
success (res) {
//.可以保存该截屏图片
// console.log(res)
//.保存到手机
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success(res2){
console.log('==截图保存=success=',res2)
callback(true)
},
fail(res2){
console.log('==截图保存=fail=',res2)
callback(null)
}
})
}
})
}else{
//2.0.1新版本截图
var cameraNode = new cc.Node('camera');
cameraNode.parent = cc.director.getScene().getChildByName('Canvas');
var camera = cameraNode.addComponent(cc.Camera);
//.要截取的范围(全屏)
let texture = new cc.RenderTexture();
// 如果截图内容中不包含 Mask 组件,可以不用传递第三个参数
let gl = cc.game._renderContext;
texture.initWithSize(cc.visibleRect.width, cc.visibleRect.height, gl.STENCIL_INDEX8);
camera.targetTexture = texture;
this.texture = texture;
let width = this.texture.width;
let height = this.texture.height;
let canvas = document.createElement('canvas');
let ctx = canvas.getContext('2d');
canvas.width = width;
canvas.height = height;
camera.render();
let data = this.texture.readPixels();
let rowBytes = width * 4;
for (let row = 0; row < height; row++) {
let srow = height - 1 - row;
let imageData = ctx.createImageData(width, 1);
let start = srow*width*4;
for (let i = 0; i < rowBytes; i++) {
imageData.data[i] = data[start+i];
}
ctx.putImageData(imageData, 0, row);
}
var dataURL = canvas.toDataURL("image/jpeg");
var tempFilePath = canvas.toTempFilePathSync({
x: 0,
y: 0,
width: width,
height: height,
destWidth: width,
destHeight: height,
});
//.保存到手机
wx.saveImageToPhotosAlbum({
filePath: tempFilePath,
success(res2){
console.log('==截图保存=success=',res2)
callback(true)
},
fail(res2){
console.log('==截图保存=fail=',res2)
callback(null)
}
})
}
}
};
// module.exports = sdk;
window.sdk = sdk;
{
"ver": "1.0.5",
"uuid": "3de1dd24-b97a-411d-91d3-1a8107767de0",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
var sdk_conf = {
dev_platform: 'weixin',
//.游戏唯一标识
game: 'zuiqiangchijiwang',
//.当前游戏版本
version: '1.005',
//.banner广告单元id
bannerAdUnitId: '',
//.video广告单元id
videoAdUnitId: '',
};
module.exports = sdk_conf;
{
"ver": "1.0.5",
"uuid": "9644e70b-5be5-4c5c-b05c-c936feed0c02",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"experimentalDecorators": true
},
"exclude": [
"node_modules",
".vscode",
"library",
"local",
"settings",
"temp"
]
}
\ No newline at end of file
{
"engine": "cocos-creator-js",
"packages": "packages"
}
\ No newline at end of file
{
"start-scene": "current",
"group-list": [
"default"
],
"collision-matrix": [
[
true
]
],
"excluded-modules": [],
"design-resolution-width": 960,
"design-resolution-height": 640,
"fit-width": false,
"fit-height": true,
"use-project-simulator-setting": false,
"simulator-orientation": false,
"use-customize-simulator": false,
"simulator-resolution": {
"width": 960,
"height": 640
},
"cocos-analytics": {
"enable": false,
"appID": "13798",
"appSecret": "959b3ac0037d0f3c2fdce94f8421a9b2"
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment