difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
"use strict";
cc._RF.push(module, '2d077OaeBRL8JWTIOk7HYAN', 'wx_sdk');
// Scripts/sdks/wx_sdk.js
 
"use strict";
 
// window.PLATFORM = "wx";        // 平台号
// window.PACKAGE_VERSION = "0.0.2";
// window.CHANNEL = "h5sszg_wx";  // 渠道号
window.PACKAGE_NAME = "闪烁之光口袋版"; // 渠道号
 
var LoginController = require("login_controller");
 
var RoleController = require("role_controller");
 
var sha1 = require('sha1.min');
 
var WXSDK = function WXSDK() {
  wx = null;
}; // 7dec9c4e4c26c46cf1a4e28a083f82bd
 
 
WXSDK.account_info = null;
WXSDK.user_info = null; // 游戏加载完成、初始化SDK
 
WXSDK.initSDK = function () {
  console.log("微信SDK相关");
  console.log(window);
  if (!window.wx) return;
  this.initTopInfo();
  wx.setKeepScreenOn({
    keepScreenOn: true
  });
  wx.onShow(function (res) {
    wx.setKeepScreenOn({
      keepScreenOn: true
    });
  });
  wx.onHide(function (res) {
    wx.setKeepScreenOn({
      keepScreenOn: false
    });
  });
  wx.showShareMenu({
    success: function success() {
      wx.onShareAppMessage(function () {
        return {
          title: '闪烁之光',
          imageUrl: '' // 图片 URL
 
        };
      });
    }
  });
  wx.getSetting({
    success: function success(res) {
      cc.log(res);
 
      if (res.authSetting["scope.userInfo"]) {
        WXSDK.checkLoginStatus();
      } else {
        var info = wx.getSystemInfoSync();
        var button = wx.createUserInfoButton({
          type: 'text',
          text: '',
          style: {
            left: 0,
            bottom: 0,
            width: info.screenWidth,
            height: info.screenHeight / 2,
            lineHeight: 40,
            backgroundColor: '',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: 16,
            borderRadius: 4
          }
        });
        button.show();
        button.onTap(function (res) {
          button.hide();
          WXSDK.checkLoginStatus();
          console.log(res);
        });
      }
    }
  });
};
 
WXSDK.initTopInfo = function () {
  var menuInfo = wx.getMenuButtonBoundingClientRect();
  var systemInfo = wx.getSystemInfoSync();
  window.WX_FIT = menuInfo.top / systemInfo.screenHeight * 0.8 || 0;
  console.log("微信小游戏菜单栏的适配值");
  cc.log(WX_FIT);
};
 
WXSDK.checkLoginStatus = function () {
  // 获取本地key
  try {
    var value = this.account_info = wx.getStorageSync('account_info');
 
    if (value) {
      WXSDK.checkSessionKey(value);
    } else {
      WXSDK.login();
    }
  } catch (e) {// Do something when catch error
  }
};
 
WXSDK.login = function () {
  if (window.wx) {
    wx.login({
      success: function success(res) {
        if (res.code) {
          //发起网络请求
          cc.log("初始化登录信息返回");
          cc.log(res);
          wx.request({
            url: 'https://s1-wx-h5sszg.shiyuegame.com/api.php/pf/wx/login/',
            method: "POST",
            data: {
              js_code: res.code,
              cps: "wxtest"
            },
            header: {
              'content-type': 'application/json' // 默认值
 
            },
            success: function success(res) {
              cc.log("服务器登录信息返回");
              cc.log(res);
 
              if (res && res.data) {
                if (res.data.error == 666) {
                  // 请求成功
                  try {
                    console.log("保存用户信息到本地");
                    cc.log(res.data.msg);
                    WXSDK.account_info = res.data.msg;
                    wx.setStorageSync('account_info', res.data.msg); // 请求成功开始登录游戏
 
                    WXSDK.initUserInfo();
                  } catch (e) {}
                }
              }
            }
          });
        } else {
          console.log('登录失败!' + res.errMsg);
        }
      }
    });
  }
};
 
WXSDK.checkSessionKey = function (data) {
  cc.log("校验key是否过期");
  wx.checkSession({
    success: function success() {
      // 没有失效,继续登录
      WXSDK.initUserInfo();
    },
    fail: function fail() {
      // session_key 已经失效,需要重新执行登录流程
      WXSDK.login();
    }
  }); // wx.getUserInfo({
  //   success: function(res) {
  //     console.log("用户信息");
  //     console.log(res)
  //     // 请求access_token
  //     cc.log("发送到服务器校验是否过期");
  //     cc.log(data);
  //     wx.request({
  //       url: 'http://s1-release-h5sszg.shiyuegame.com/api.php/pf/wx/token',
  //       data: {
  //         cps: "wxtest"
  //       },
  //       header: {
  //         'content-type': 'application/json' // 默认值
  //       },
  //       success (res1) {
  //         if (res1 && res1.data) {
  //           cc.log("ASSESS_TOKEN返回");
  //           cc.log(res1);
  //           if (res1.data.error == 666) {    // 请求成功
  //             cc.log("校验ASSESS_TOKEN是否过期");
  //             var signature = sha1(res.rawData + data.session_key)
  //             wx.request({
  //               url: 'http://s1-release-h5sszg.shiyuegame.com/api.php/pf/wx/check_session',
  //               data: {
  //                 access_token: res1.data.msg.access_token,
  //                 openid: data.openid,
  //                 signature: signature,
  //                 cps: "wxtest",
  //               },
  //               header: {
  //                 'content-type': 'application/json' // 默认值
  //               },
  //               success (res) {
  //                 cc.log("校验结果");
  //                 cc.log(res);
  //                 if (res && res.data) {
  //                   if (res.data.error == 666) {    // 请求成功
  //                     try {
  //                         console.log("HHHHHHHHHHHHHHHHHHHHHHHHH");
  //                         console.log("校验成功开始登录游戏");
  //                     } catch (e) {
  //                     }
  //                   }
  //                 }
  //               }
  //             })
  //           }
  //         }
  //       }
  //     })
  //   },
  //   fail: function(res) {
  //     console.log("UUUUUUUUUUUUUUUUu");
  //     console.log(res)
  //   }
  // })
};
 
WXSDK.initUserInfo = function () {
  wx.getUserInfo({
    success: function success(res) {
      WXSDK.user_info = res;
      cc.log("获取用户信息成功");
      cc.log(res);
      WXSDK.setLoginData(res);
    },
    fail: function fail(res) {
      cc.log("获取用户信息失败");
    }
  });
};
 
WXSDK.setLoginData = function (user_info) {
  this.user_info = user_info;
  this.sdkBackLogin();
}; // SDK登录成功回调
 
 
WXSDK.sdkBackLogin = function () {
  var login_data = {};
  login_data.usrName = "wx_" + this.account_info.openid;
  login_data.password = "wx123456";
  console.log("微信数据初始花成功,开始请求服务器列表");
  LoginController.getInstance().loginPlatformRequest(login_data);
};
 
WXSDK.pay = function (money, buyNum, prodId, productName, productDesc, extension, coinNum) {
  console.log("开始调用支付");
  var loginInfo = LoginController.getInstance().model.getLoginInfo();
  var roleVo = RoleController.getInstance().getRoleVo();
  if (roleVo == null) return;
  var severInfo = roleVo.srv_id.split("_");
  var platform = severInfo[0] || "";
  var zone_id = severInfo[1];
  var systemInfo = wx.getSystemInfoSync();
  var systemName = systemInfo.system;
  var pf = "";
 
  if (systemName.indexOf("iOS") > -1) {// return;
  } else if (systemName.indexOf("Android") > -1) {
    pf = "android";
  }
 
  var data = {
    openid: WXSDK.account_info.openid,
    time: WXSDK.account_info.time,
    sign: WXSDK.account_info.sign,
    zone_id: zone_id,
    pf: pf,
    cps: "wxtest"
  };
  wx.request({
    url: "https://" + loginInfo.host + "/api.php/pf/wx/balance",
    method: "POST",
    data: data,
    header: {
      'content-type': 'application/json' // 默认值
 
    },
    success: function success(res) {
      console.log("请求余额", res);
 
      if (res && res.data) {
        if (res.data.error == 666) {
          // 请求成功
          try {
            //时间戳
            var date_time = Math.ceil(Date.now() / 1000);
            productName = productName || money * 10 + "钻石";
            var cps = "wxtest";
            var channel = CHANNEL;
 
            var _extension = roleVo.rid + "$$" + platform + "$$" + zone_id + "$$" + channel + "$$" + prodId + "$$" + productName + "$$" + cps + "$$" + date_time;
 
            cc.log("拓展参数_extension==>", _extension);
 
            var base_64 = require("base64").Base64;
 
            _extension = base_64.encode(_extension);
            cc.log("拓展参数_extension==222222222>", _extension);
 
            if (res.data.msg) {
              if (res.data.msg.balance >= money * 10) {
                wx.request({
                  url: "https://" + loginInfo.host + "/api.php/pf/wx/pay",
                  method: "POST",
                  data: {
                    openid: WXSDK.account_info.openid,
                    zone_id: zone_id,
                    pf: pf,
                    amt: money * 10,
                    time: WXSDK.account_info.time,
                    sign: WXSDK.account_info.sign,
                    app_remark: _extension,
                    cps: cps
                  },
                  header: {
                    'content-type': 'application/json' // 默认值
 
                  },
                  success: function success(res) {
                    console.log("预下单返回");
                    console.log(res);
 
                    if (res && res.data) {
                      if (res.data.error == 666) {// 请求成功
                      } else if (res.data.error == 1) {} else if (res.data.error == -1) {
                        console.log("充值失败");
                      }
                    }
                  }
                });
              } else {
                wx.requestMidasPayment({
                  mode: "game",
                  env: 1,
                  //
                  offerId: "1450021881",
                  currencyType: "CNY",
                  platform: pf,
                  buyQuantity: money * 10,
                  zoneId: zone_id,
                  success: function success(res) {
                    console.log("支付回调成功");
                    wx.request({
                      url: "https://" + loginInfo.host + "/api.php/pf/wx/pay",
                      method: "POST",
                      data: {
                        openid: WXSDK.account_info.openid,
                        zone_id: zone_id,
                        pf: pf,
                        amt: money * 10,
                        time: WXSDK.account_info.time,
                        sign: WXSDK.account_info.sign,
                        app_remark: _extension,
                        cps: cps
                      },
                      header: {
                        'content-type': 'application/json' // 默认值
 
                      },
                      success: function success(res) {
                        console.log("预下单返回");
                        console.log(res);
 
                        if (res && res.data) {
                          if (res.data.error == 666) {// 请求成功
                          } else if (res.data.error == 1) {} else if (res.data.error == -1) {
                            console.log("充值失败");
                          }
                        }
                      }
                    });
                  },
                  fail: function fail(res) {
                    console.log("支付回调失败", res);
                  },
                  complete: function complete(res) {
                    console.log("支付回调complete", res);
                  }
                });
              }
            }
          } catch (e) {}
        }
      }
    }
  });
};
 
WXSDK.loginGame = function () {
  var test_acount = LoginController.getInstance().getTestAccount();
  cc.log("使用了微信测试账号");
  cc.log(test_acount); // SDK请求登录游戏
 
  var login_data = {};
 
  if (test_acount) {
    login_data.account = test_acount;
  } else {
    login_data.account = "wx_" + this.account_info.openid;
  }
 
  login_data.rawData = this.user_info.rawData;
  login_data.signature = this.user_info.signature;
  login_data.channel = CHANNEL;
  login_data.package_name = PACKAGE_NAME;
  login_data.package_version = PACKAGE_VERSION;
  login_data.platform = PLATFORM;
  login_data.token = WXSDK.account_info.session_key;
  login_data.timestamp = WXSDK.account_info.time;
  login_data.sign = WXSDK.account_info.sign;
  LoginController.getInstance().cusSDKLogin(login_data);
}; // 通知服务器成功
 
 
WXSDK.submitLogin = function (url) {
  if (url) {
    var submit_url = "https://" + url + "/api.php/pf/wx/session";
    console.log(submit_url);
    console.log(WXSDK.account_info);
    wx.request({
      url: submit_url,
      method: "POST",
      data: {
        session_key: WXSDK.account_info.session_key,
        openid: WXSDK.account_info.openid,
        time: WXSDK.account_info.time,
        sign: WXSDK.account_info.sign,
        cps: "wxtest"
      },
      header: {
        'content-type': 'application/json' // 默认值
 
      },
      success: function success(res) {
        cc.log("服务器登录信息返回");
        cc.log(res);
 
        if (res && res.data) {
          console.log(res.data);
 
          if (res.data.error == 666) {// 请求成功
          }
        }
      }
    });
  }
};
 
WXSDK.getCurrChannel = function () {};
 
WXSDK.getSubChannel = function () {};
 
WXSDK.loginLog = function () {
  var options = wx.getLaunchOptionsSync();
  console.log("xhj------------", options);
  if (options == null || options.query == null || options.query.weixinadinfo == null) return;
  var weixinadinfoArr = options.query.weixinadinfo.split(".");
  var aid = weixinadinfoArr[0];
  if (aid == null) return;
  var url = window.location.href;
  console.log("xhj+++++++++++++", url);
  wx.request({
    url: "",
    method: "POST",
    data: {
      sku: options.query.sku,
      app_id: options.query.app_id,
      sy_ad_id: options.query.sy_ad_id,
      channel_id: options.query.channel_id,
      gdt_vid: options.query.gdt_vid,
      weixinadinfo: options.query.weixinadinfo,
      sub_ad_id: aid,
      url: url
    },
    header: {
      'content-type': 'application/json' // 默认值
 
    },
    success: function success(res) {
      console.log("上报登录信息返回");
      console.log(res);
    }
  });
};
 
WXSDK.download_qrcode_png = function () {
  wx.request({
    url: 'https://s1-h5mlf-h5sszg.shiyuegame.com/api.php/pf/wx/token',
    method: "POST",
    data: {
      cps: "wxtest"
    },
    header: {
      'content-type': 'application/json' // 默认值
 
    },
    success: function success(res1) {
      if (res1.data.error == 666) {
        // 请求成功
        //res1.data.msg.access_token,
        console.log("获取assess_token");
        console.log(res1);
        var query = wx.getLaunchOptionsSync();
        var scene = decodeURIComponent(query.scene);
        console.log("获取小游戏scene");
        console.log(query);
        console.log(scene);
        console.log("请求二维码相关");
      }
    }
  });
};
 
WXSDK.createGameClubButton = function () {
  var clubButton = wx.createGameClubButton({
    icon: 'green',
    style: {
      left: 10,
      top: 76,
      width: 40,
      height: 40
    }
  });
};
 
module.exports = WXSDK;
 
cc._RF.pop();