Commit 6ff6be98ac1a74933826b9502e6013fbca7e0b30
1 parent
be22f0b1
Exists in
master
and in
3 other branches
X
Showing
18 changed files
with
160 additions
and
418 deletions
Show diff stats
sdk/SDKTools.ts
| ... | ... | @@ -110,47 +110,10 @@ export class SDKTools { |
| 110 | 110 | * 插屏 |
| 111 | 111 | */ |
| 112 | 112 | static createInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { |
| 113 | - if (!this.isWx) return | |
| 114 | - WXSDK.ad.createInterstitialAd(adUnitId); | |
| 113 | + if (!this.isWx) return Promise.resolve({ code: 1, msg: "暂无广告" }) | |
| 114 | + return WXSDK.ad.createInterstitialAd(adUnitId); | |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - | |
| 118 | - /** | |
| 119 | - * 格子广告 | |
| 120 | - * @param adUnitId 格子广告ID | |
| 121 | - * @param opts { //非必填 默认满屏居低 | |
| 122 | - * bannerWidth: | |
| 123 | - * offsetY: 距离底部多远 | |
| 124 | - * isOff:是否默认不显示 | |
| 125 | - * } | |
| 126 | - */ | |
| 127 | - static createGrid(key: string, adUnitId: string = GAMEDATA.gridId, opts?: { gridCount?: number; bannerWidth?: number, offsetY: number; adIntervals?: number, isOff?: boolean }) { | |
| 128 | - if (!this.isWx) return | |
| 129 | - return WXSDK.ad.createGrid(key, adUnitId, opts); | |
| 130 | - } | |
| 131 | - /** | |
| 132 | - * 格子广告 显示 ps:创建默认显示 | |
| 133 | - */ | |
| 134 | - static showGrid(key: string) { | |
| 135 | - if (!this.isWx) return | |
| 136 | - WXSDK.ad.showGrid(key) | |
| 137 | - } | |
| 138 | - /** | |
| 139 | - * 格子广告 隐藏 | |
| 140 | - */ | |
| 141 | - static hideGrid(key: string) { | |
| 142 | - if (!this.isWx) return | |
| 143 | - WXSDK.ad.hideGrid(key) | |
| 144 | - } | |
| 145 | - /** | |
| 146 | - * 格子广告 销毁 | |
| 147 | - */ | |
| 148 | - static destoryGrid(key: string) { | |
| 149 | - if (!this.isWx) return | |
| 150 | - WXSDK.ad.destoryGrid(key) | |
| 151 | - } | |
| 152 | - | |
| 153 | - | |
| 154 | 117 | /** |
| 155 | 118 | * 原生模板广告 全局只能存在一个 并且创建的位置最好是同一个位置 通过show hide控制 如果要改变位置,调用destory再调用创建(不建议频繁销毁创建,会导致广告拉取不到) |
| 156 | 119 | * @param adUnitId 格子广告ID | ... | ... |
wxsdk/WXSDK.ts
wxsdk/base/SDKConst.ts
| 1 | 1 | // 游戏配置数据 只需要改动这里的配置信息 |
| 2 | 2 | // 游戏配置数据 只需要改动这里的配置信息 |
| 3 | 3 | export const GAMEDATA = { |
| 4 | - game_id: '10001',//游戏id | |
| 4 | + game_id: '10001',//游戏id | |
| 5 | 5 | channel_id: '10001',//渠道id 暂时和游戏id一致 |
| 6 | 6 | version: '1.0.1', //版本号 中台控制正式还是测试服,尽量保持和小游戏版本一致 |
| 7 | 7 | appkey: 'd959274a83ea3b95bd1d9b765683eff6',//中台appkey |
| ... | ... | @@ -35,9 +35,15 @@ export const GAMEDATA = { |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | // sdk版本 |
| 38 | -export const SDKVersion = 'v1.0.2'; | |
| 38 | +export const SDKVersion = 'v1.0.3'; | |
| 39 | 39 | // 是否打印 |
| 40 | 40 | export const __LOG__ = false; |
| 41 | +// 是否mock | |
| 42 | +export var sdkEnv = { | |
| 43 | + isDebug: false | |
| 44 | +}; | |
| 45 | + | |
| 46 | + | |
| 41 | 47 | |
| 42 | 48 | //游戏基础信息 |
| 43 | 49 | export const VersionHost = 'https://wxsdk-ver.d3games.com/version'; |
| ... | ... | @@ -62,6 +68,11 @@ export const OrderHost = { |
| 62 | 68 | Prod: 'https://wxsdk-order.d3games.com/', |
| 63 | 69 | Pre: 'https://wxsdk-order-pre.d3games.com/', |
| 64 | 70 | }; |
| 71 | +// gm接口 | |
| 72 | +export const GMHost = { | |
| 73 | + Prod: 'https://hermes.d3games.com/', | |
| 74 | + Pre: 'http://wxadmin.pre.d3games.com/', | |
| 75 | +}; | |
| 65 | 76 | |
| 66 | 77 | export const HostKeys = { |
| 67 | 78 | //打点服务器 |
| ... | ... | @@ -96,11 +107,11 @@ export const HostKeys = { |
| 96 | 107 | adList: 'api/adplan/list', //广告计划列表 |
| 97 | 108 | behavior: 'api/douyin/behavior', //抖音投放关键行为 |
| 98 | 109 | attribute: 'api/member/attribute/set', //修改用户属性 |
| 99 | - | |
| 100 | 110 | //订单 |
| 101 | 111 | orderReport: 'api/order/v2/mimas', //订单信息上报 |
| 102 | 112 | orderQuery: 'api/order/query', //订单信息查询 |
| 103 | - preorder: 'api/order/v2/preorder' //获取支付方式 | |
| 113 | + preorder: 'api/order/v2/preorder', //获取支付方式 | |
| 114 | + | |
| 104 | 115 | }; |
| 105 | 116 | |
| 106 | 117 | // 本地存储keys |
| ... | ... | @@ -175,4 +186,4 @@ export const SceneCode = { |
| 175 | 186 | // sdk系统默认分享id |
| 176 | 187 | export const SDKDotType = { |
| 177 | 188 | Share: 1001 // 会话进入,无渠道ID |
| 178 | -}; | |
| 179 | 189 | \ No newline at end of file |
| 190 | +}; | ... | ... |
wxsdk/http/SDKApi.ts
| ... | ... | @@ -5,71 +5,70 @@ import DataService from "../service/DataService"; |
| 5 | 5 | |
| 6 | 6 | export class SDKApi { |
| 7 | 7 | |
| 8 | - public static Version = (...args) => SDKHttp.httpPost(`${VersionHost}`, ...args); | |
| 8 | + public static Version = (...args) => SDKHttp.httpPost(`${VersionHost}`, "", ...args); | |
| 9 | 9 | |
| 10 | 10 | //GameApi |
| 11 | - public static ShareList = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.ShareList}`, ...args); | |
| 11 | + public static ShareList = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.ShareList, ...args); | |
| 12 | 12 | |
| 13 | - public static getConfig = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.getConfig}`, ...args); | |
| 13 | + public static getConfig = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.getConfig, ...args); | |
| 14 | 14 | //订阅 |
| 15 | - public static subscribe = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.subscribe}`, ...args); | |
| 15 | + public static subscribe = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.subscribe, ...args); | |
| 16 | 16 | // |
| 17 | - public static saveData = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.saveData}`, ...args); | |
| 18 | - public static getData = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.getData}`, ...args); | |
| 17 | + public static saveData = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.saveData, ...args); | |
| 18 | + public static getData = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.getData, ...args); | |
| 19 | 19 | //排行榜添加分数 废弃 |
| 20 | - public static rankAdd = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.rankAdd}`, ...args); | |
| 20 | + public static rankAdd = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.rankAdd, ...args); | |
| 21 | 21 | //排行榜添加分数 |
| 22 | - public static totalrankAdd = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.totalrankAdd}`, ...args); | |
| 22 | + public static totalrankAdd = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.totalrankAdd, ...args); | |
| 23 | 23 | //排行榜 废弃 |
| 24 | - public static rankList = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.rankList}`, ...args); | |
| 24 | + public static rankList = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.rankList, ...args); | |
| 25 | 25 | //排行榜 |
| 26 | - public static totalrankList = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.totalrankList}`, ...args); | |
| 26 | + public static totalrankList = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.totalrankList, ...args); | |
| 27 | 27 | //广告计划列表 |
| 28 | - public static adList = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.adList}`, ...args); | |
| 28 | + public static adList = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.adList, ...args); | |
| 29 | 29 | // |
| 30 | - public static behavior = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.behavior}`, ...args); | |
| 30 | + public static behavior = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.behavior, ...args); | |
| 31 | 31 | //修改用户属性 |
| 32 | - public static attribute = (...args) => SDKHttp.httpPost(`${DataService.I.GameApi}${HostKeys.attribute}`, ...args); | |
| 33 | - | |
| 32 | + public static attribute = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.attribute, ...args); | |
| 34 | 33 | |
| 35 | 34 | //LoginApi |
| 36 | - public static Login = (...args) => SDKHttp.httpPost(`${DataService.I.LoginApi}${HostKeys.Login}`, ...args); | |
| 35 | + public static Login = (...args) => SDKHttp.httpPost(DataService.I.LoginApi, HostKeys.Login, ...args); | |
| 37 | 36 | |
| 38 | - public static reftoken = (...args) => SDKHttp.httpPost(`${DataService.I.LoginApi}${HostKeys.Reftoken}`, ...args); | |
| 37 | + public static reftoken = (...args) => SDKHttp.httpPost(DataService.I.LoginApi, HostKeys.Reftoken, ...args); | |
| 39 | 38 | |
| 40 | - public static weakLogin = (...args) => SDKHttp.httpPost(`${DataService.I.LoginApi}${HostKeys.weakLogin}`, ...args); | |
| 39 | + public static weakLogin = (...args) => SDKHttp.httpPost(DataService.I.LoginApi, HostKeys.weakLogin, ...args); | |
| 41 | 40 | |
| 42 | 41 | |
| 43 | 42 | //DotApi |
| 44 | - // public static dot = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.Dot}`, ...args); | |
| 43 | + // public static dot = (...args) => SDKHttp.httpGet(DataService.I.DotApi,HostKeys.Dot, ...args); | |
| 44 | + | |
| 45 | + public static logOut = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.logOut, ...args); | |
| 46 | + | |
| 47 | + public static loadingFinish = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.loadingFinish, ...args); | |
| 45 | 48 | |
| 46 | - public static logOut = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.logOut}`, ...args); | |
| 49 | + public static active = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.Active, ...args); | |
| 47 | 50 | |
| 48 | - public static loadingFinish = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.loadingFinish}`, ...args); | |
| 51 | + public static share = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.Share, ...args); | |
| 49 | 52 | |
| 50 | - public static active = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.Active}`, ...args); | |
| 53 | + public static adStat = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.AdStat, ...args); | |
| 51 | 54 | |
| 52 | - public static share = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.Share}`, ...args); | |
| 55 | + public static stay = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.stay, ...args); | |
| 53 | 56 | |
| 54 | - public static adStat = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.AdStat}`, ...args); | |
| 57 | + public static behaviors = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.behaviors, ...args); | |
| 55 | 58 | |
| 56 | - public static stay = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.stay}`, ...args); | |
| 59 | + public static dot = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.dot, ...args); | |
| 57 | 60 | |
| 58 | - public static behaviors = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.behaviors}`, ...args); | |
| 61 | + public static jumps = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.jumps, ...args); | |
| 59 | 62 | |
| 60 | - public static dot = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.dot}`, ...args); | |
| 63 | + public static level = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.level, ...args); | |
| 61 | 64 | |
| 62 | - public static jumps = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.jumps}`, ...args); | |
| 65 | + public static role = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.role, ...args); | |
| 63 | 66 | |
| 64 | - public static level = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.level}`, ...args); | |
| 65 | - | |
| 66 | - public static role = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.role}`, ...args); | |
| 67 | - | |
| 68 | - public static client_log = (...args) => SDKHttp.httpGet(`${DataService.I.DotApi}${HostKeys.client_log}`, ...args); | |
| 67 | + public static client_log = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.client_log, ...args); | |
| 69 | 68 | |
| 70 | 69 | |
| 71 | 70 | // OrderApi |
| 72 | - public static pay = (...args) => SDKHttp.httpPost(`${DataService.I.OrderApi}${HostKeys.orderReport}`, ...args); | |
| 73 | - public static orderQuery = (...args) => SDKHttp.httpPost(`${DataService.I.OrderApi}${HostKeys.orderQuery}`, ...args); | |
| 74 | - public static preorder = (...args) => SDKHttp.httpPost(`${DataService.I.OrderApi}${HostKeys.preorder}`, ...args); | |
| 71 | + public static pay = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderReport, ...args); | |
| 72 | + public static orderQuery = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderQuery, ...args); | |
| 73 | + public static preorder = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.preorder, ...args); | |
| 75 | 74 | } | ... | ... |
wxsdk/http/SDKHttp.ts
| 1 | -import { GAMEDATA } from "../base/SDKConst"; | |
| 1 | +import { GAMEDATA, sdkEnv } from "../base/SDKConst"; | |
| 2 | 2 | import SignUtils from "../utils/SignUtils"; |
| 3 | 3 | |
| 4 | 4 | export default class SDKHttp { |
| ... | ... | @@ -91,17 +91,32 @@ export default class SDKHttp { |
| 91 | 91 | } |
| 92 | 92 | xhr.timeout = 3000; |
| 93 | 93 | xhr.send(data); |
| 94 | - | |
| 95 | - | |
| 96 | - | |
| 97 | 94 | }); |
| 98 | 95 | } |
| 99 | 96 | |
| 100 | - public static async httpGet(url: string, data?: any, dataType: "json" | "string" = "json") { | |
| 97 | + public static withMock(url: string) { | |
| 98 | + return sdkEnv.isDebug && window["MOCK"] && window["MOCK"][url]; | |
| 99 | + } | |
| 100 | + public static mockData(url: string): Promise<IResult<any>> { | |
| 101 | + let responseText = window["MOCK"][url] | |
| 102 | + return Promise.resolve({ code: +responseText.code, data: responseText.data, msg: responseText.msg }); | |
| 103 | + } | |
| 104 | + | |
| 105 | + public static async httpGet(baseUrl: string, url: string, data?: any, dataType: "json" | "string" = "json") { | |
| 106 | + if (this.withMock(url)) { | |
| 107 | + return this.mockData(url); | |
| 108 | + } | |
| 109 | + | |
| 110 | + url = baseUrl + url; | |
| 101 | 111 | return this.httpRequest(url, "GET", data, dataType); |
| 102 | 112 | } |
| 103 | 113 | |
| 104 | - public static httpPost(url: string, data?: any, dataType: "json" | "string" = "json") { | |
| 114 | + public static httpPost(baseUrl: string, url: string, data?: any, dataType: "json" | "string" = "json") { | |
| 115 | + if (this.withMock(url)) { | |
| 116 | + return this.mockData(url); | |
| 117 | + } | |
| 118 | + | |
| 119 | + url = baseUrl + url; | |
| 105 | 120 | return this.httpRequest(url, "POST", data, dataType); |
| 106 | 121 | } |
| 107 | 122 | } |
| 108 | 123 | \ No newline at end of file | ... | ... |
wxsdk/service/AdService.ts
| 1 | 1 | import WxApi from "../wx/WxApi"; |
| 2 | 2 | import WxBanner from "../wx/WxBanner"; |
| 3 | -import WxGrid from "../wx/WxGrid"; | |
| 4 | 3 | import WxCustom from "../wx/WxCustom"; |
| 5 | 4 | import WxInterstitial from "../wx/WxInterstitial"; |
| 6 | 5 | import { GAMEDATA } from "../base/SDKConst"; |
| ... | ... | @@ -44,36 +43,7 @@ export default class AdService { |
| 44 | 43 | * @param adUnitId |
| 45 | 44 | */ |
| 46 | 45 | createInterstitialAd(adUnitId: string) { |
| 47 | - WxInterstitial.showInterstitialAd(adUnitId) | |
| 48 | - // let interstitialAd = WxApi.I.createInterstitialAd(adUnitId); | |
| 49 | - // interstitialAd.show(); | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * 创建格子广告 | |
| 54 | - * @param adUnitId | |
| 55 | - * @param opts | |
| 56 | - */ | |
| 57 | - createGrid(key: string, adUnitId: string, opts?: { gridCount?: number; bannerWidth?: number, offsetY: number; adIntervals?: number }) { | |
| 58 | - return WxGrid.I.create(key, adUnitId, opts); | |
| 59 | - } | |
| 60 | - /** | |
| 61 | - * 格子广告 显示 ps:创建默认显示 | |
| 62 | - */ | |
| 63 | - showGrid(key: string) { | |
| 64 | - WxGrid.I.show(key) | |
| 65 | - } | |
| 66 | - /** | |
| 67 | - * 格子广告 隐藏 | |
| 68 | - */ | |
| 69 | - hideGrid(key: string) { | |
| 70 | - WxGrid.I.hide(key); | |
| 71 | - } | |
| 72 | - /** | |
| 73 | - * 格子广告 销毁 | |
| 74 | - */ | |
| 75 | - destoryGrid(key: string) { | |
| 76 | - WxGrid.I.destory(key); | |
| 46 | + return WxInterstitial.showInterstitialAd(adUnitId) | |
| 77 | 47 | } |
| 78 | 48 | |
| 79 | 49 | /** | ... | ... |
wxsdk/service/DataService.ts
| 1 | 1 | import SdkData from "./entity/SdkData"; |
| 2 | 2 | import SDKUtils from "../utils/SDKUtils"; |
| 3 | 3 | import StorageUtils from "../utils/StorageUtils"; |
| 4 | -import { StorageKeys, GAMEDATA, LoginHost, GameHost, DotHost, OrderHost } from "../base/SDKConst"; | |
| 4 | +import { StorageKeys, GAMEDATA, LoginHost, GameHost, DotHost, OrderHost, GMHost } from "../base/SDKConst"; | |
| 5 | 5 | import { Gender, NetworkType } from "../base/SDKEnum"; |
| 6 | 6 | import WxLaunch from "../wx/WxLaunch"; |
| 7 | 7 | |
| ... | ... | @@ -15,7 +15,7 @@ export default class DataService { |
| 15 | 15 | this._data = new SdkData; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - private setValue(key: string, val: any) { | |
| 18 | + setValue(key: string, val: any) { | |
| 19 | 19 | // console.error(key,val) |
| 20 | 20 | if (SDKUtils.isUndefined(val)) |
| 21 | 21 | return; |
| ... | ... | @@ -33,7 +33,6 @@ export default class DataService { |
| 33 | 33 | setLoginData(data: _LoginInnerData) { |
| 34 | 34 | if (!data || Object.keys(data).length === 0) |
| 35 | 35 | return; |
| 36 | - | |
| 37 | 36 | if (data.hasOwnProperty('openId')) |
| 38 | 37 | this.setOpenId(data.openId); |
| 39 | 38 | |
| ... | ... | @@ -232,10 +231,6 @@ export default class DataService { |
| 232 | 231 | return this; |
| 233 | 232 | } |
| 234 | 233 | |
| 235 | - // get NetworkType(): NetworkType { | |
| 236 | - // return this._data.networkType; | |
| 237 | - // } | |
| 238 | - | |
| 239 | 234 | setNetworkType(networkType: NetworkType) { |
| 240 | 235 | this.setValue('networkType', networkType); |
| 241 | 236 | return this; |
| ... | ... | @@ -411,6 +406,13 @@ export default class DataService { |
| 411 | 406 | return path; |
| 412 | 407 | } |
| 413 | 408 | |
| 409 | + get GMApi() { | |
| 410 | + let path = GMHost.Prod; | |
| 411 | + if (this.EnvEnum === 1) { | |
| 412 | + path = GMHost.Pre; | |
| 413 | + } | |
| 414 | + return path; | |
| 415 | + } | |
| 414 | 416 | |
| 415 | 417 | get GameId() { |
| 416 | 418 | return GAMEDATA.game_id; |
| ... | ... | @@ -502,22 +504,6 @@ export default class DataService { |
| 502 | 504 | return this; |
| 503 | 505 | } |
| 504 | 506 | |
| 505 | - // get ShareTotalNum(): number { | |
| 506 | - // return IntegralService.I.getFinishShareNum(); | |
| 507 | - // } | |
| 508 | - | |
| 509 | - // get VideoTotalNum(): number { | |
| 510 | - // return IntegralService.I.getFinishVideoNum(); | |
| 511 | - // } | |
| 512 | - | |
| 513 | - // get ShareDayNum(): number { | |
| 514 | - // return LocalService.I.getDayAllShareNum(); | |
| 515 | - // } | |
| 516 | - | |
| 517 | - // get VideoDayNum(): number { | |
| 518 | - // return LocalService.I.getDayAllVideoNum(); | |
| 519 | - // } | |
| 520 | - | |
| 521 | 507 | private timeInterval |
| 522 | 508 | public updateTodayOnlineTime() { |
| 523 | 509 | let dot = StorageUtils.I.get("pcsdk_today_online_time_300") || 0; | ... | ... |
wxsdk/service/GameService.ts
| ... | ... | @@ -8,7 +8,7 @@ import WxSystem from "../wx/WxSystem"; |
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | export default class GameService { |
| 11 | - private constructor() { | |
| 11 | + public constructor() { | |
| 12 | 12 | |
| 13 | 13 | } |
| 14 | 14 | |
| ... | ... | @@ -84,18 +84,12 @@ export default class GameService { |
| 84 | 84 | status: 1, |
| 85 | 85 | id, |
| 86 | 86 | }) |
| 87 | + resolve({ code: 0, msg: '订阅成功!' }) | |
| 87 | 88 | } |
| 88 | - // GameService.I.subScribe(acceptKeys) | |
| 89 | - // .then(() => { | |
| 90 | - // resolve(ret); | |
| 91 | - // DebugUtils.I.dynamic('====> PCSDK subScribe订阅消息成功', ret); | |
| 92 | - // }) | |
| 93 | - // .catch((err) => reject(err || { errCode: 0, errMsg: 'GameApi subScribe请求错误' })); | |
| 94 | 89 | |
| 95 | 90 | }) |
| 96 | 91 | .catch(err => reject(err)); |
| 97 | 92 | }); |
| 98 | - // return WxApi.I.subscribeMessage(template_ids); | |
| 99 | 93 | } |
| 100 | 94 | |
| 101 | 95 | /** |
| ... | ... | @@ -130,7 +124,7 @@ export default class GameService { |
| 130 | 124 | /** |
| 131 | 125 | * 构建登录/弱登录公用参数 |
| 132 | 126 | */ |
| 133 | - private buildParams2() { | |
| 127 | + public buildParams2() { | |
| 134 | 128 | let gameid = GAMEDATA.game_id; |
| 135 | 129 | let channel = DataService.I.ChannelId; |
| 136 | 130 | let brand = WxSystem.I.brand; |
| ... | ... | @@ -174,13 +168,13 @@ export default class GameService { |
| 174 | 168 | token |
| 175 | 169 | }) |
| 176 | 170 | } |
| 177 | - | |
| 171 | + | |
| 178 | 172 | |
| 179 | 173 | |
| 180 | 174 | /** |
| 181 | 175 | * 构建登录/弱登录公用参数 |
| 182 | 176 | */ |
| 183 | - private buildParams() { | |
| 177 | + public buildParams() { | |
| 184 | 178 | let gameid = GAMEDATA.game_id; |
| 185 | 179 | let channel = DataService.I.ChannelId; |
| 186 | 180 | let uid = DataService.I.UserId; |
| ... | ... | @@ -195,7 +189,7 @@ export default class GameService { |
| 195 | 189 | }; |
| 196 | 190 | } |
| 197 | 191 | |
| 198 | - private static instance: GameService; | |
| 192 | + public static instance: GameService; | |
| 199 | 193 | static get I(): GameService { |
| 200 | 194 | return this.instance || (this.instance = new GameService()); |
| 201 | 195 | } | ... | ... |
wxsdk/service/LogService.ts
| ... | ... | @@ -465,8 +465,25 @@ export default class LogService { |
| 465 | 465 | cacheUserId: StorageUtils.I.get("userId") || "0", |
| 466 | 466 | level: LogLevel[level], |
| 467 | 467 | content |
| 468 | - // level: | |
| 469 | 468 | }) |
| 469 | + switch (level) { | |
| 470 | + case LogLevel.error: | |
| 471 | + console.error(content); | |
| 472 | + break; | |
| 473 | + case LogLevel.debug: | |
| 474 | + console.log(content); | |
| 475 | + break; | |
| 476 | + case LogLevel.info: | |
| 477 | + console.info(content); | |
| 478 | + break; | |
| 479 | + case LogLevel.warning: | |
| 480 | + console.warn(content); | |
| 481 | + break; | |
| 482 | + default: | |
| 483 | + console.log(content); | |
| 484 | + break; | |
| 485 | + } | |
| 486 | + | |
| 470 | 487 | } |
| 471 | 488 | |
| 472 | 489 | ... | ... |
wxsdk/service/entity/SdkData.ts
| ... | ... | @@ -39,7 +39,7 @@ export default class SdkData { |
| 39 | 39 | public logindays: number; // 登录天数 |
| 40 | 40 | public amount: number; // 充值金额 |
| 41 | 41 | public pon: number; // 用户类型:1微信投放2抖音3自然量0未知 |
| 42 | - public ptm:number; // 当天是否300s | |
| 42 | + public ptm: number; // 当天是否300s | |
| 43 | 43 | public cule_token: string; // 用户通过广告调起微信小游戏的唯一编码 |
| 44 | 44 | public creative_id: string; // 创意ID |
| 45 | 45 | public advertister_id: string; // 广告账户ID |
| ... | ... | @@ -85,10 +85,10 @@ export default class SdkData { |
| 85 | 85 | this.amount = 0; |
| 86 | 86 | this.pon = 0; |
| 87 | 87 | this.ptm = 0; |
| 88 | - this.cule_token =''; | |
| 89 | - this.creative_id =''; | |
| 90 | - this.advertister_id =''; | |
| 91 | - this.request_id =''; | |
| 88 | + this.cule_token = ''; | |
| 89 | + this.creative_id = ''; | |
| 90 | + this.advertister_id = ''; | |
| 91 | + this.request_id = ''; | |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | ... | ... |
wxsdk/utils/SignUtils.ts
| ... | ... | @@ -71,12 +71,12 @@ export default class SignUtils { |
| 71 | 71 | let query = ''; |
| 72 | 72 | for (let i = 0, len = keys.length; i < len; i++) { |
| 73 | 73 | // 为空,为 0的参数不参与签名,参数名为ver,pkv的参数不参与签名, 字符集为 utf-8 |
| 74 | - if (params[keys[i]] === '' || params[keys[i]] === '0' || params[keys[i]] === 0 || keys[i] === 'ver'|| keys[i] === 'pkv') continue | |
| 74 | + if (params[keys[i]] === '' || params[keys[i]] === '0' || params[keys[i]] === 0 || keys[i] === 'ver' || keys[i] === 'pkv') continue | |
| 75 | 75 | key = keys[i]; |
| 76 | 76 | i && (query += ''); |
| 77 | - if(SDKUtils.isArray(params[key])){ | |
| 77 | + if (SDKUtils.isArray(params[key])) { | |
| 78 | 78 | query += `${key}=${JSON.stringify(params[key])}`; |
| 79 | - }else{ | |
| 79 | + } else { | |
| 80 | 80 | query += `${key}=${params[key]}`; |
| 81 | 81 | } |
| 82 | 82 | } | ... | ... |
wxsdk/wx/WxApi.ts
| ... | ... | @@ -41,7 +41,7 @@ export default class WxApi { |
| 41 | 41 | subscribeMessage(tmplIds: Array<string>) { |
| 42 | 42 | let version = Version.I.getVSubscribeMessage(); |
| 43 | 43 | if (!this.canIUse(version)) return Promise.reject(this.getVersionError(version)); |
| 44 | - console.log("tmplIds",tmplIds) | |
| 44 | + // console.log("tmplIds", tmplIds) | |
| 45 | 45 | return new Promise((resolve, reject) => { |
| 46 | 46 | wx.requestSubscribeMessage({ |
| 47 | 47 | tmplIds, |
| ... | ... | @@ -412,4 +412,5 @@ export default class WxApi { |
| 412 | 412 | static get I(): WxApi { |
| 413 | 413 | return this._instance || (this._instance = new WxApi); |
| 414 | 414 | } |
| 415 | -} | |
| 416 | 415 | \ No newline at end of file |
| 416 | + | |
| 417 | +} | ... | ... |
wxsdk/wx/WxCustom.ts
| ... | ... | @@ -86,7 +86,7 @@ export default class WxCustom { |
| 86 | 86 | // console.log("that.isEnd", this.isEnd, this.customAd) |
| 87 | 87 | if (this.customAd) { |
| 88 | 88 | LogService.I.adStat('custom', this.adUnitId, DOT_AD_TYPE.custom, DOT_AD_STATUS.show) |
| 89 | - this.customAd.show().then(res=>{ | |
| 89 | + this.customAd.show().then(res => { | |
| 90 | 90 | WxCustom.I.handleQueue(); |
| 91 | 91 | }).catch((err: any) => this.handleShowError(err)); |
| 92 | 92 | __LOG__ && console.error('WxCustom - show: ' + this.adUnitId, this.customAd); |
| ... | ... | @@ -166,7 +166,7 @@ export default class WxCustom { |
| 166 | 166 | let that = WxCustom.I; |
| 167 | 167 | that.unbind(); |
| 168 | 168 | that._isErrored = true; |
| 169 | - if(that.customAd){ | |
| 169 | + if (that.customAd) { | |
| 170 | 170 | that.customAd.destroy() |
| 171 | 171 | } |
| 172 | 172 | that.customAd = null | ... | ... |
wxsdk/wx/WxGrid.ts
| ... | ... | @@ -1,233 +0,0 @@ |
| 1 | -import WxSystem from "./WxSystem"; | |
| 2 | -import SDKUtils from "../utils/SDKUtils"; | |
| 3 | -import { BannerError, __LOG__ } from "../base/SDKConst"; | |
| 4 | -import LogService from "../service/LogService"; | |
| 5 | -import { DOT_AD_STATUS, DOT_AD_TYPE } from "../base/SDKEnum"; | |
| 6 | - | |
| 7 | -/* | |
| 8 | -* banner | |
| 9 | -*/ | |
| 10 | -export default class WxGrid { | |
| 11 | - private static instance: WxGrid; | |
| 12 | - static get I(): WxGrid { | |
| 13 | - return this.instance || (this.instance = new WxGrid(750, 750)); | |
| 14 | - } | |
| 15 | - private designWidth: number; | |
| 16 | - private bannerWidth: number; | |
| 17 | - private bannerHeight: number; | |
| 18 | - private bannerScale: number; | |
| 19 | - private bannerParams: any; | |
| 20 | - private _isErrored: boolean; | |
| 21 | - private adUnitId: string; | |
| 22 | - private gridAd: any; | |
| 23 | - private resolve: any; | |
| 24 | - private reject: any; | |
| 25 | - private AdList: object | |
| 26 | - | |
| 27 | - constructor(designWidth: number, bannerWidth: number) { | |
| 28 | - designWidth = designWidth || 750; | |
| 29 | - bannerWidth = bannerWidth || 750; | |
| 30 | - | |
| 31 | - this.AdList = {} | |
| 32 | - this.adUnitId = ''; | |
| 33 | - this._isErrored = false; | |
| 34 | - this.designWidth = designWidth; | |
| 35 | - this.bannerScale = WxSystem.I.winWidth / this.designWidth; | |
| 36 | - this.bannerWidth = Math.max(this.bannerScale * bannerWidth, 300); | |
| 37 | - this.bannerHeight = WxSystem.I.winHeight / this.bannerScale; | |
| 38 | - } | |
| 39 | - | |
| 40 | - get isErrored() { | |
| 41 | - return this._isErrored; | |
| 42 | - } | |
| 43 | - | |
| 44 | - create(key: string, adUnitId: string, opts?: { gridCount?: number; bannerWidth?: number, offsetY: number; adIntervals?: number }) { | |
| 45 | - this.bannerParams = opts || {}; | |
| 46 | - this.AdList[key] = { | |
| 47 | - ...opts, | |
| 48 | - adUnitId, | |
| 49 | - key, | |
| 50 | - isEnd: false, | |
| 51 | - queue: [] | |
| 52 | - } | |
| 53 | - if (opts && opts.bannerWidth) { | |
| 54 | - this.bannerWidth = opts.bannerWidth; | |
| 55 | - } | |
| 56 | - this.bannerParams.type = this.bannerParams.type || 1; | |
| 57 | - this.bannerParams.gridCount = this.bannerParams.gridCount || 5; | |
| 58 | - this.bannerParams.offsetY = -this.bannerParams.offsetY || 0; | |
| 59 | - this.bannerParams.adIntervals = this.bannerParams.adIntervals || 60; | |
| 60 | - return new Promise((resolve, reject) => { | |
| 61 | - this.resolve = resolve; | |
| 62 | - this.reject = reject; | |
| 63 | - this._isErrored = false; | |
| 64 | - this.adUnitId = adUnitId; | |
| 65 | - | |
| 66 | - if (SDKUtils.isEmpty(adUnitId)) | |
| 67 | - return this.reject({ ...BannerError.BannerInvalid, adUnitId: this.adUnitId }); | |
| 68 | - | |
| 69 | - // 设置样式(hack:修复qq版本) | |
| 70 | - this.bannerParams.type === 2 && (this.bannerWidth = WxSystem.I.winWidth); | |
| 71 | - let style = { top: 0, left: (WxSystem.I.winWidth - this.bannerWidth) / 2, width: this.bannerWidth }; | |
| 72 | - style = { | |
| 73 | - ...style, | |
| 74 | - top: 0 + this.bannerParams.offsetY | |
| 75 | - }; | |
| 76 | - if (this.AdList[key].gridAd) { | |
| 77 | - if (this.AdList[key].isOff) { | |
| 78 | - this.show(key) | |
| 79 | - } | |
| 80 | - resolve() | |
| 81 | - return | |
| 82 | - } | |
| 83 | - // 创建并判断是否存在 | |
| 84 | - this.gridAd = wx.createGridAd({ adUnitId, style: { left: style.left, top: this.bannerHeight }, gridCount: this.bannerParams.gridCount, }); | |
| 85 | - LogService.I.adStat('grid', adUnitId, DOT_AD_TYPE.grid, DOT_AD_STATUS.request) | |
| 86 | - if (!this.gridAd) | |
| 87 | - return this.reject({ ...BannerError.BannerNotOpen, adUnitId: this.adUnitId }); | |
| 88 | - this.AdList[key].gridAd = this.gridAd; | |
| 89 | - this.gridAd.onLoad(this.onLoad); | |
| 90 | - this.gridAd.onError(this.onError); | |
| 91 | - this.gridAd.onResize(this.onResize); | |
| 92 | - if (!this.AdList[key].isOff) { | |
| 93 | - this.show(key); | |
| 94 | - } | |
| 95 | - }); | |
| 96 | - } | |
| 97 | - | |
| 98 | - show(key: string): boolean { | |
| 99 | - if (this.AdList[key].gridAd) { | |
| 100 | - if (this.AdList[key].isEnd) { | |
| 101 | - let fun = (key) => { | |
| 102 | - WxGrid.I.show(key) | |
| 103 | - } | |
| 104 | - this.AdList[key].queue.push(fun); | |
| 105 | - return | |
| 106 | - } | |
| 107 | - this.AdList[key].isEnd = true; | |
| 108 | - | |
| 109 | - if (this.AdList[key].gridAd.style.realHeight) | |
| 110 | - this.AdList[key].gridAd.style.top = WxSystem.I.winHeight - this.AdList[key].gridAd.style.realHeight + this.AdList[key].offsetY; | |
| 111 | - if (this.bannerParams.type === 2) { | |
| 112 | - if (this.AdList[key].gridAd.style.width) | |
| 113 | - this.AdList[key].gridAd.style.left = (WxSystem.I.winWidth - this.AdList[key].gridAd.style.width) / 2; | |
| 114 | - else | |
| 115 | - this.AdList[key].gridAd.style.left = (WxSystem.I.winWidth - this.bannerWidth) / 2; | |
| 116 | - } else | |
| 117 | - this.AdList[key].gridAd.style.left = (WxSystem.I.winWidth - this.bannerWidth) / 2; | |
| 118 | - | |
| 119 | - LogService.I.adStat('grid', this.AdList[key].adUnitId, DOT_AD_TYPE.grid, DOT_AD_STATUS.show) | |
| 120 | - this.AdList[key].gridAd.show().catch((err: any) => this.handleShowError(err)); | |
| 121 | - this.onResize(); | |
| 122 | - __LOG__ && console.error('WxGrid - show: ' + this.adUnitId, this.AdList[key].gridAd.style); | |
| 123 | - WxGrid.I.handleQueue(key) | |
| 124 | - return true; | |
| 125 | - } | |
| 126 | - WxGrid.I.handleQueue(key) | |
| 127 | - return false; | |
| 128 | - } | |
| 129 | - | |
| 130 | - hide(key: string) { | |
| 131 | - if (this.AdList[key].gridAd) { | |
| 132 | - if (this.AdList[key].isEnd) { | |
| 133 | - let fun = (key) => { | |
| 134 | - WxGrid.I.hide(key) | |
| 135 | - } | |
| 136 | - this.AdList[key].queue.push(fun); | |
| 137 | - return | |
| 138 | - } | |
| 139 | - this.AdList[key].isEnd = true; | |
| 140 | - this.AdList[key].gridAd.style.left = -9999; | |
| 141 | - this.AdList[key].gridAd.hide(); | |
| 142 | - LogService.I.adStat('grid', this.AdList[key].adUnitId, DOT_AD_TYPE.grid, DOT_AD_STATUS.interrupt); | |
| 143 | - __LOG__ && console.error('WxGrid - hide: ' + this.adUnitId); | |
| 144 | - | |
| 145 | - WxGrid.I.handleQueue(key) | |
| 146 | - } | |
| 147 | - } | |
| 148 | - | |
| 149 | - destory(key: string) { | |
| 150 | - if (this.AdList[key] && this.AdList[key].gridAd) { | |
| 151 | - this.AdList[key].gridAd.style.left = -9999; | |
| 152 | - this.AdList[key].gridAd.destroy(); | |
| 153 | - this.AdList[key].gridAd = null; | |
| 154 | - LogService.I.adStat('grid', this.AdList[key].adUnitId, DOT_AD_TYPE.grid, DOT_AD_STATUS.interrupt) | |
| 155 | - __LOG__ && console.error('WxGrid - destory: ' + this.AdList[key].adUnitId); | |
| 156 | - } | |
| 157 | - } | |
| 158 | - | |
| 159 | - private onLoad() { | |
| 160 | - let that = WxGrid.I; | |
| 161 | - let gridAd = that.gridAd; | |
| 162 | - if (!gridAd) return; | |
| 163 | - // Platform.IsQQ && that.show(); | |
| 164 | - __LOG__ && console.error('WxGrid - onLoad: ' + that.adUnitId); | |
| 165 | - if (gridAd.style.realHeight) { | |
| 166 | - gridAd.style.top = WxSystem.I.winHeight - gridAd.style.realHeight + that.bannerParams.offsetY; | |
| 167 | - gridAd.style.left = (WxSystem.I.winWidth - gridAd.style.realWidth) / 2; | |
| 168 | - } | |
| 169 | - | |
| 170 | - that.unbind(); | |
| 171 | - that.resolve && that.resolve({ | |
| 172 | - adUnitId: that.adUnitId, | |
| 173 | - scale: that.bannerScale, | |
| 174 | - width: gridAd.style.realWidth / that.bannerScale, | |
| 175 | - height: gridAd.style.realHeight / that.bannerScale | |
| 176 | - }); | |
| 177 | - } | |
| 178 | - | |
| 179 | - private onError(err: any) { | |
| 180 | - __LOG__ && console.error('WxGrid - onError', err); | |
| 181 | - let that = WxGrid.I; | |
| 182 | - !that._isErrored && that.handleError(err, { ...BannerError.BannerFail, adUnitId: that.adUnitId }); | |
| 183 | - } | |
| 184 | - | |
| 185 | - private onResize() { | |
| 186 | - let that = WxGrid.I; | |
| 187 | - let gridAd = that.gridAd; | |
| 188 | - if (!gridAd) return; | |
| 189 | - gridAd.style.top = WxSystem.I.winHeight - gridAd.style.realHeight + that.bannerParams.offsetY; | |
| 190 | - gridAd.style.left = (WxSystem.I.winWidth - gridAd.style.realWidth) / 2; | |
| 191 | - } | |
| 192 | - | |
| 193 | - private handleShowError(ret: { errCode: number; errMsg: string }) { | |
| 194 | - __LOG__ && console.error('WxGrid - handleShowError', ret); | |
| 195 | - let that = WxGrid.I; | |
| 196 | - let { errCode, errMsg } = ret; | |
| 197 | - !that.isErrored && that.handleError(ret, { code: errCode, msg: errMsg }); | |
| 198 | - } | |
| 199 | - | |
| 200 | - private handleError(ret: any, err: any) { | |
| 201 | - let that = WxGrid.I; | |
| 202 | - that.unbind(); | |
| 203 | - if (that.gridAd) { | |
| 204 | - that.gridAd.destroy() | |
| 205 | - } | |
| 206 | - that.gridAd = null; | |
| 207 | - that._isErrored = true; | |
| 208 | - that.reject && that.reject({ ...err, adUnitId: that.adUnitId }); | |
| 209 | - LogService.I.adStat('grid', that.adUnitId, DOT_AD_TYPE.grid, DOT_AD_STATUS.fail) | |
| 210 | - __LOG__ && console.error('WxGrid - onError: ' + that.adUnitId); | |
| 211 | - } | |
| 212 | - | |
| 213 | - private unbind() { | |
| 214 | - if (this.gridAd) { | |
| 215 | - this.gridAd.offLoad(this.onLoad); | |
| 216 | - this.gridAd.offError(this.onError); | |
| 217 | - this.gridAd.offResize(this.onResize); | |
| 218 | - } | |
| 219 | - } | |
| 220 | - /** | |
| 221 | - * 处队列 | |
| 222 | - */ | |
| 223 | - handleQueue(key) { | |
| 224 | - let that = WxGrid.I; | |
| 225 | - if (that.AdList[key].queue.length > 0) { | |
| 226 | - that.AdList[key].isEnd = false; | |
| 227 | - let fn = that.AdList[key].queue.shift(); | |
| 228 | - fn(); | |
| 229 | - } else { | |
| 230 | - that.AdList[key].isEnd = false; | |
| 231 | - } | |
| 232 | - } | |
| 233 | -} | |
| 234 | 0 | \ No newline at end of file |
wxsdk/wx/WxInit.ts
| ... | ... | @@ -55,7 +55,7 @@ export default class WxInit { |
| 55 | 55 | fromChannel = infoArr[0]; |
| 56 | 56 | } |
| 57 | 57 | // 设置抖音投放转化跟踪 |
| 58 | - if(ad_id){ | |
| 58 | + if (ad_id) { | |
| 59 | 59 | fromChannel = ad_id; |
| 60 | 60 | } |
| 61 | 61 | |
| ... | ... | @@ -85,7 +85,7 @@ export default class WxInit { |
| 85 | 85 | .setCreativeId(creative_id) |
| 86 | 86 | .setAdvertisterId(advertister_id) |
| 87 | 87 | .setRequestId(request_id) |
| 88 | - //cule_token=cule_token123&creative_id=creative_id213&ad_id=ad_id9999&request_id=request_id456&advertister_id=advertister_id9876 | |
| 88 | + //cule_token=cule_token123&creative_id=creative_id213&ad_id=ad_id9999&request_id=request_id456&advertister_id=advertister_id9876 | |
| 89 | 89 | // 设置网络类型 |
| 90 | 90 | WxApi.I.getNetworkType() |
| 91 | 91 | .then((ret: _NetworkTypeSuccessObject) => this.setNetworkType(ret)) | ... | ... |
wxsdk/wx/WxInterstitial.ts
| ... | ... | @@ -18,33 +18,49 @@ export default class WxInterstitial { |
| 18 | 18 | |
| 19 | 19 | /** 显示插屏广告 */ |
| 20 | 20 | public static showInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { |
| 21 | - this.interstitialAdId = adUnitId; | |
| 22 | - if (!this.interstitialSuccell) { | |
| 23 | - this.createInterstitial(true); | |
| 24 | - return; | |
| 25 | - } | |
| 26 | - this.interstitialAd.show(); | |
| 27 | - LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.show) | |
| 28 | - setTimeout(() => { | |
| 29 | - this.createInterstitial(false); | |
| 30 | - }, 5000); | |
| 21 | + return new Promise(async (resolve, reject) => { | |
| 22 | + this.interstitialAdId = adUnitId; | |
| 23 | + if (!this.interstitialSuccell) { | |
| 24 | + this.createInterstitial(true, resolve); | |
| 25 | + return; | |
| 26 | + } | |
| 27 | + this.interstitialAd.show().then(suc => { | |
| 28 | + resolve && resolve({ code: 0, msg: "展示成功!" }); | |
| 29 | + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.show) | |
| 30 | + }).catch((err) => { | |
| 31 | + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) | |
| 32 | + resolve && resolve({ code: err.errCode, msg: err.errMsg }); | |
| 33 | + }) | |
| 34 | + }) | |
| 31 | 35 | } |
| 32 | 36 | |
| 33 | 37 | /** 创建插屏广告 */ |
| 34 | - private static createInterstitial(isShow: boolean = false) { | |
| 38 | + private static createInterstitial(isShow: boolean = false, resolve?) { | |
| 35 | 39 | LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.request) |
| 36 | 40 | this.interstitialAd = WxApi.I.createInterstitialAd(this.interstitialAdId); |
| 37 | - this.interstitialAd.onLoad(() => { | |
| 41 | + this.interstitialAd.onLoad(async () => { | |
| 38 | 42 | WxInterstitial.interstitialSuccell = true; |
| 39 | 43 | LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.rt) |
| 40 | 44 | if (isShow) { |
| 41 | - this.interstitialAd.show(); | |
| 42 | - LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.show) | |
| 45 | + this.interstitialAd.show().then(suc => { | |
| 46 | + resolve && resolve({ code: 0, msg: "展示成功!" }); | |
| 47 | + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.show) | |
| 48 | + }).catch((err) => { | |
| 49 | + WxInterstitial.interstitialSuccell = false; | |
| 50 | + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) | |
| 51 | + resolve && resolve({ code: err.errCode, msg: err.errMsg }); | |
| 52 | + }) | |
| 43 | 53 | } |
| 44 | 54 | }) |
| 45 | 55 | this.interstitialAd.onError(err => { |
| 46 | 56 | LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) |
| 47 | 57 | WxInterstitial.interstitialSuccell = false; |
| 58 | + resolve && resolve({ code: err.errCode, msg: err.errMsg }); | |
| 48 | 59 | }) |
| 60 | + | |
| 61 | + this.interstitialAd.onClose(call => { | |
| 62 | + this.createInterstitial(false); | |
| 63 | + }) | |
| 64 | + | |
| 49 | 65 | } |
| 50 | 66 | } |
| 51 | 67 | \ No newline at end of file | ... | ... |
wxsdk/wx/WxLogin.ts
| ... | ... | @@ -16,7 +16,7 @@ export default class WxLogin { |
| 16 | 16 | * tip1:如果是重新登录,需要把之前的token清空 |
| 17 | 17 | * tip2:必须先调用wxLogin才能使用getUserInfo |
| 18 | 18 | */ |
| 19 | - async login(isAuthorize: boolean): Promise<any> { | |
| 19 | + async login(isAuthorize: boolean): Promise<any> { | |
| 20 | 20 | return new Promise(async (resolve, reject) => { |
| 21 | 21 | let code = await WxApi.I.login(); |
| 22 | 22 | if (isAuthorize) { |
| ... | ... | @@ -94,7 +94,7 @@ export default class WxLogin { |
| 94 | 94 | if (data) { |
| 95 | 95 | // 设置登录信息 |
| 96 | 96 | if (data.data) { |
| 97 | - let { channel, uid, firstlogin, token, reftoken, openid, expire, isnew, gameconfig,logindays,amount,pon} = data.data; | |
| 97 | + let { channel, uid, firstlogin, token, reftoken, openid, expire, isnew, gameconfig, logindays, amount, pon } = data.data; | |
| 98 | 98 | LogService.I.setLogind({ |
| 99 | 99 | channel, |
| 100 | 100 | userId: uid, |
| ... | ... | @@ -114,7 +114,11 @@ export default class WxLogin { |
| 114 | 114 | this.isFirst = true; |
| 115 | 115 | LogService.I.share(DataService.I.ShareKey, DataService.I.ShareId, DOT_SHARE_TYPE.click); |
| 116 | 116 | } |
| 117 | - this.handleExpire(expire) | |
| 117 | + try { //修改时间后会报错,未找到原因 | |
| 118 | + this.handleExpire(expire) | |
| 119 | + } catch (error) { | |
| 120 | + console.log("handleExpire_error", error) | |
| 121 | + } | |
| 118 | 122 | ShareVideoService.I.forward() |
| 119 | 123 | } |
| 120 | 124 | } | ... | ... |
wxsdk/wx/WxPay.ts