123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- import HTTPS, { NetPost } from "../HTTPS";
- export class WeChatSDKManager {
- private loginData = {};
- private logincode = '';
- login(callBack: Function) {
- let wx = (window as any)["wx"];
- let self = this;
- wx.login({
- success: (login_res) => {
- self.logincode = login_res.code;
- console.log("得到登录凭证code");
- console.log(login_res.code);
- let sysInfo = wx.getSystemInfoSync();
- let width = sysInfo.screenWidth;
- let height = sysInfo.screenHeight;
- wx.getSetting({
- success(getSetting_res) {
- console.log("wx.getSetting获取用户配置成功");
- if (getSetting_res.authSetting['scope.userInfo']) {
- wx.getUserInfo({
- success: function (res) {
- console.log("得到用户信息数据");
- console.log(getSetting_res);
- self.loginData = res.userInfo;
- self.requestGameServer()
- callBack?.(res);
- }
- })
- } else {
- let button = wx.createUserInfoButton({
- type: 'text',
- text: '',
- style: {
- left: 0,
- top: 0,
- width: width,
- height: height,
- lineHeight: height,
- // backgroundColor: '#ff0000',
- color: '#000000',
- textAlign: 'center',
- fontSize: 18,
- borderRadius: 4
- }
- })
- // _disNode.active = true;
- button.onTap((res) => {
- // 用户同意授权后回调,通过回调可获取用户头像昵称信息
- console.log("用户点击后_得到用户信息数据");
- console.log(res);
- self.loginData = res.userInfo;
- self.requestGameServer()
- callBack?.(res);
- button.hide();
- })
- button.show();
- }
- },
- // 失败回调
- fail(res) {
- console.log("wx.getSetting获取用户配置失败");
- console.log(res);
- },
- // 结束回调(调用成功,失败都会执行)
- complete(res) {
- console.log("wx.getSetting获取用户配置结束");
- console.log(res);
- }
- })
- }
- });
- }
- requestGameServer() {
- HTTPS.Instance.post(NetPost.Login,
- {
- platform: 'wechatmini',
- code: this.logincode,
- avatar: this.loginData['avatarUrl'],
- nickname: this.loginData['nickName'],
- }).then((resp) => {
- console.error('999999999999');
- console.error(resp);
- HTTPS.Instance.token = resp.data.userinfo.token
- })
- }
- showShareMenu() {
- let wx = (window as any)["wx"];
- wx.showShareMenu({
- menus: ['shareAppMessage', "shareTimeline"],
- })
- wx.onShareAppMessage(function () {
- return {
- title: '你能挑战过吗?',
- imageUrl: ""
- }
- })
- if (wx.onShareTimeline != null) {
- wx.onShareTimeline(function () {
- return {
- title: '你能挑战过吗?',
- imageUrl: ""
- }
- })
- }
- }
- ///////////////////
- private rewardVideo2
- public show_video(callback: Function) {
- let wx = (window as any)["wx"];
- let id = "adunit-36fec0fa8e78f37b"
- if (id == '') {
- callback(true);
- return;
- }
- if (this.rewardVideo2 != null) {
- this.rewardVideo2.offClose(fun);
- }
- let rewardedVideoAd = wx.createRewardedVideoAd({
- adUnitId: id,
- });
- this.rewardVideo2 = rewardedVideoAd;
- rewardedVideoAd.load().then(() => {
- wx.showToast({
- title: "加载中,请稍后",
- icon: 'success',//图标,支持"success"、"loading"
- duration: 1500,//提示的延迟时间,单位毫秒,默认:1500
- mask: false,//是否显示透明蒙层,防止触摸穿透,默认:false
- success: function () { },
- fail: function () { },
- complete: function () { }
- })
- console.log('激励视频 广告加载成功');
- rewardedVideoAd.show();
- });
- rewardedVideoAd.onError(err => {
- console.log('激励视频 广告显示失败', err);
- wx.showToast({
- title: "请稍后再试",
- icon: 'fail',//图标,支持"success"、"loading"
- duration: 1500,//提示的延迟时间,单位毫秒,默认:1500
- mask: false,//是否显示透明蒙层,防止触摸穿透,默认:false
- success: function () { },
- fail: function () { },
- complete: function () { }
- })
- callback(false);
- })
- var fun = function (res) {
- if (res && res.isEnded) {
- console.log('res: ', res);
- callback(true);
- rewardedVideoAd.offClose(fun);
- } else {
- console.log('播放中途退出');
- callback(false);
- }
- }
- rewardedVideoAd.onClose(fun);
- }
- }
|