123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- //app.js
- var http = require('http/request.js');
- App({
- data: {
- loginInfo: null,
- hasLogin:false,
- userId:'',
- channel:"blackWhite3",
- code:'',
- audios: [[
- "/assets/audio/c1.mp3",
- "/assets/audio/c1.mp3",
- "/assets/audio/d1.mp3",
- "/assets/audio/c1.mp3",
- "/assets/audio/f1.mp3",
- "/assets/audio/e1.mp3",
- "/assets/audio/c1.mp3",
- "/assets/audio/c1.mp3",
- "/assets/audio/d1.mp3",
- "/assets/audio/c1.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/f1.mp3",
- "/assets/audio/c1.mp3",
- "/assets/audio/c1.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/f1.mp3",
- "/assets/audio/e1.mp3",
- "/assets/audio/d1.mp3",
- "/assets/audio/_a1.mp3",
- "/assets/audio/_a1.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/f1.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/f1.mp3"
- ],[
- "/assets/audio/e2.mp3",
- "/assets/audio/_d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/_d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/c1.mp3",
- "/assets/audio/e1.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/e1.mp3",
- "/assets/audio/_g1.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/e1.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/_d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/_d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/_d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/c1.mp3",
- "/assets/audio/e1.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/e1.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/a1.mp3"
- ],[
- "/assets/audio/g1.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/a1.mp3",
- "/assets/audio/g1.mp3"
- ],[
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3"
- ],[
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3"
- ],[
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/b1.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/g1.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/g2.mp3",
- "/assets/audio/f2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/e2.mp3",
- "/assets/audio/d2.mp3",
- "/assets/audio/c2.mp3",
- "/assets/audio/c2.mp3"
- ]],
- shareMsg: "发现一个很有趣的音乐游戏,一起来玩玩看~",
- failed: false,
- shareIcon: [
- "https://small-app.oss-cn-beijing.aliyuncs.com/black-white/shandian.png",
- "https://small-app.oss-cn-beijing.aliyuncs.com/black-white/xiaobang.png",
- "https://small-app.oss-cn-beijing.aliyuncs.com/black-white/zuoyoushou.png",
- "https://small-app.oss-cn-beijing.aliyuncs.com/black-white/huaxiele.png",
- "https://small-app.oss-cn-beijing.aliyuncs.com/black-white/shoucan.png",
- "https://small-app.oss-cn-beijing.aliyuncs.com/black-white/tiyulaoshi.png"
- ],
- currentShareIcon: "",
- shareTicket: "",
- },
- onLaunch: function () {
- // 展示本地存储能力
- },
- //页面现实加载,获取群信息
- onShow: function (options) {
- this.data.shareTicket = options.shareTicket;
- },
- // 登录
- login(callback) {
- var that = this;
- wx.login({
- success: res => {
- // 发送 res.code 到后台换取 openId, sessionKey, unionId
- if (res.code) {
- //发起网络请求
- console.log(res.code)
- that.data.code = res.code;
- wx.getSetting({
- success: (res) => {
- if (res.authSetting["scope.userInfo"]) {
- //已经授权
- that.getUserInfo(callback);
- } else {
- //没有授权
- wx.authorize({
- scope: 'scope.userInfo',
- success: function () {
- that.getUserInfo(callback);
- },
- fail: function () {
- //用户拒绝授权
- that.authFailed(callback);
- }
- })
- }
- }
- })
- } else {
- console.log("获取用户登录态失败!" + res.errMsg)
- that.login(callback);
- }
- }
- })
- },
- //获取用户信息
- getUserInfo(callback) {
- var that = this;
- wx.getUserInfo({
- success: res => {
- console.log(res)
- that.data.loginInfo = {
- 'code': that.data.code,
- 'wechatName': res.userInfo.nickName,
- 'wechatHeadUrl': res.userInfo.avatarUrl,
- 'encryptedData': res.encryptedData,
- 'channel': that.data.channel,
- 'iv': res.iv
- }
- //登录服务器
- that.hostLogin(callback);
- wx.setStorage({
- key: 'userInfo',
- data: res.userInfo
- })
- callback();
- // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
- // 所以此处加入 callback 以防止这种情况
- if (this.userInfoReadyCallback) {
- this.userInfoReadyCallback(res)
- }
- },
- fail: function (e) {
- console.log("获取用户信息失败")
- }
- })
- },
- //用户拒绝授权
- authFailed(callback) {
- var that = this;
- wx.showModal({
- title: '提示',
- content: '您当前尚未登录,请点击“授权”完成授权方能进入游戏!',
- confirmText: "授权",
- showCancel: false,//隐藏取消按钮
- success: function (res) {
- //调取授权弹窗成功
- if (res.confirm) {
- //点击确认进入授权页面
- wx.openSetting({
- success: function (res) {
- console.log(res)
- if (!res.authSetting["scope.userInfo"]) {
- //这里是授权失败
- that.authFailed(callback)
- } else {
- //授权成功
- that.getUserInfo(callback)
- }
- }
- })
- } else if (res.cancel) {
- //用户拒绝授权
- that.authFailed(callback);
- }
- },
- fail() {
- //调取授权弹窗失败
- that.checkSession(callback);
- }
- })
- },
- //检测当前用户登录态是否有效
- checkSession(callback) {
- var that = this;
- if(this.data.hasLogin == true){
- callback();
- return;
- }
- wx.checkSession({
- success: function () {
- that.login(callback);
- },
- fail: function () {
- //登录态过期
- console.log("过期了")
- that.login(callback)//重新登录;
- }
- })
- },
-
- hostLogin(callback) {
- var that = this;
- this.func.req('/user/loginByWechatApplet', 'get', {}, this.data.loginInfo, function (res) {
- console.log(res)
- if (res.code == 0) {
- that.data.userId=res.data.userId;
- wx.setStorage({
- key: "userId",
- data: res.data.userId
- })
- that.data.userId = res.data.userId;
- that.data.hasLogin = true;
- wx.setStorageSync("hasLogin", "1")
- callback();
- }
- })
- },
- globalData: {
- userInfo: null
- },
- func: {
- req: http.req
- },
- //上报成绩事件
- reportGameScore: function (gameType,score) {
- var that = this;
- http.req('/blackwhite/reportGameScore', 'get', "userId=" + that.data.userId, {
- userId: that.data.userId,
- channel: that.data.channel,
- gameType: gameType,
- score: score
- }, (res) => {
- console.log(res)
- })
- }
- })
|