Commit 8d5544ffa3b8675ddc03587ebfd3872e638e6a9e
1 parent
cfd1e4db
Exists in
zfb_waibu_linshi
去掉平台代码
Showing
7 changed files
with
39 additions
and
41 deletions
Show diff stats
sdk/WxHelper.ts
... | ... | @@ -14,7 +14,7 @@ export class WxHelper { |
14 | 14 | /** 微信用户信息 */ |
15 | 15 | public static userInfo: WxUserInfo; |
16 | 16 | public static get isOperable() { |
17 | - return (cc.sys.platform === cc.sys.WECHAT_GAME || cc.sys.platform === cc.sys.ALIPAY_GAME) | |
17 | + return (typeof wx !== 'undefined' || typeof my != 'undefined') | |
18 | 18 | } |
19 | 19 | |
20 | 20 | /** 获取设备信息 */ |
... | ... | @@ -191,13 +191,13 @@ export class WxHelper { |
191 | 191 | * @param time 关闭时间 |
192 | 192 | */ |
193 | 193 | public static showToast(msg: string, time: number = 1500) { |
194 | - if (cc.sys.platform === cc.sys.WECHAT_GAME) | |
194 | + if (typeof wx !== 'undefined') | |
195 | 195 | wx.showToast({ |
196 | 196 | title: msg, |
197 | 197 | icon: 'none', |
198 | 198 | duration: time |
199 | 199 | }) |
200 | - else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
200 | + else if (typeof my != 'undefined') { | |
201 | 201 | my.showToast({ |
202 | 202 | type: 'none', |
203 | 203 | content: msg, |
... | ... | @@ -397,7 +397,7 @@ export class WxHelper { |
397 | 397 | } |
398 | 398 | |
399 | 399 | public static setUserWxCloudStorage(data: object) { |
400 | - if (cc.sys.platform != cc.sys.WECHAT_GAME || !DataService.I.Authorize) return null; | |
400 | + if (typeof wx == 'undefined' || !DataService.I.Authorize) return null; | |
401 | 401 | wx.setUserCloudStorage({ |
402 | 402 | KVDataList: [{ key: 'data', value: JSON.stringify(data) }], |
403 | 403 | success: res => { |
... | ... | @@ -413,7 +413,7 @@ export class WxHelper { |
413 | 413 | return WxHelper.isOperable && AlipayApi.I.canUseRank() |
414 | 414 | } |
415 | 415 | public static getRank(key: string) { |
416 | - if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
416 | + if (typeof my != 'undefined') { | |
417 | 417 | AlipayApi.I.getRankList(key).then(() => { |
418 | 418 | console.log('success 关闭banner') |
419 | 419 | // BannerManager.I.hideAll(); |
... | ... | @@ -425,7 +425,7 @@ export class WxHelper { |
425 | 425 | |
426 | 426 | } |
427 | 427 | public static setRankScore(key: string, score: number, updateType?: number) { |
428 | - if (cc.sys.platform === cc.sys.ALIPAY_GAME) | |
428 | + if (typeof my != 'undefined') | |
429 | 429 | AlipayApi.I.setRankScoreData(key, score, updateType); |
430 | 430 | } |
431 | 431 | public static async loginWx(isAuthorize: boolean, failFunction?: Function, count?: number, success?: Function): Promise<any> { |
... | ... | @@ -452,7 +452,7 @@ export class WxHelper { |
452 | 452 | public static goToGameCenter(success: Function, fail: Function) { |
453 | 453 | //每个游戏跳转游戏中心的url 不一样 |
454 | 454 | let url = "alipays://platformapi/startapp?appId=2021003125685383&url=https%3A%2F%2Frender.alipay.com%2Fp%2Fyuyan%2F180020010001206617%2Findex.html%3FcaprMode%3Dsync&chInfo=gamesetlattice&sms=YES&appClearTop=false"; |
455 | - if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
455 | + if (typeof my != 'undefined') { | |
456 | 456 | AlipayApi.I.navigateToMiniProgramByScheme(url, success, fail) |
457 | 457 | } |
458 | 458 | } | ... | ... |
wxsdk/alipay/AlipayApi.ts
... | ... | @@ -378,7 +378,7 @@ export default class AlipayApi { |
378 | 378 | navigateToMiniProgramByScheme(scheme, success, fail) { |
379 | 379 | let { params, message } = this.schemeToParams(scheme); |
380 | 380 | console.log('params--', { ...params }); |
381 | - if (cc.sys.platform != cc.sys.ALIPAY_GAME) return | |
381 | + if (typeof my == 'undefined') return | |
382 | 382 | if (params) { |
383 | 383 | my.navigateToMiniProgram({ ...params, success, fail,}); |
384 | 384 | } else { |
... | ... | @@ -585,7 +585,7 @@ export default class AlipayApi { |
585 | 585 | //段位 |
586 | 586 | setRankSegmentData(rankKey: string, segment: number, segmentName: string) { |
587 | 587 | return new Promise((resolve, reject) => { |
588 | - if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) | |
588 | + if (typeof my == 'undefined') return reject({ errMsg: `无环境`, errCode: -1 }) | |
589 | 589 | if (!this.canIUse('10.5.6')) return reject(this.getVersionError('10.5.6')); |
590 | 590 | my.setImRankData({ |
591 | 591 | rankId: rankKey, |
... | ... | @@ -611,7 +611,7 @@ export default class AlipayApi { |
611 | 611 | setRankScoreData(rankKey: string, score: number, updateType: number = 1) { |
612 | 612 | |
613 | 613 | return new Promise((resolve, reject) => { |
614 | - if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) | |
614 | + if (typeof my == 'undefined') return reject({ errMsg: `无环境`, errCode: -1 }) | |
615 | 615 | if (!this.canIUse(this._requirementVersion.rank)) return reject(this.getVersionError(this._requirementVersion.rank)); |
616 | 616 | my.setImRankData({ |
617 | 617 | rankId: rankKey, |
... | ... | @@ -645,7 +645,7 @@ export default class AlipayApi { |
645 | 645 | */ |
646 | 646 | getRankList(rankKey: string, scorePrefix?: string, scoreSuffix?: string) { |
647 | 647 | return new Promise((resolve, reject) => { |
648 | - if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) | |
648 | + if (typeof my == 'undefined') return reject({ errMsg: `无环境`, errCode: -1 }) | |
649 | 649 | if (!this.canIUse(this._requirementVersion.rank)) return reject(this.getVersionError(this._requirementVersion.rank)); |
650 | 650 | my.getImRankList({ |
651 | 651 | rankId: rankKey, | ... | ... |
wxsdk/base/wx.d.ts
wxsdk/service/AdService.ts
... | ... | @@ -20,11 +20,11 @@ export default class AdService { |
20 | 20 | */ |
21 | 21 | createBanner(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { |
22 | 22 | |
23 | - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
23 | + if (typeof tt != 'undefined') { | |
24 | 24 | return null |
25 | - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
25 | + } else if (typeof my != 'undefined') { | |
26 | 26 | return AlipayBanner.I.create(adUnitId) |
27 | - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
27 | + } else if (typeof wx !== 'undefined') { | |
28 | 28 | return WxBanner.I.create(adUnitId, opts); |
29 | 29 | } |
30 | 30 | } |
... | ... | @@ -32,11 +32,11 @@ export default class AdService { |
32 | 32 | * banner 显示 ps:创建默认显示 |
33 | 33 | */ |
34 | 34 | showBanner() { |
35 | - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
35 | + if (typeof tt != 'undefined') { | |
36 | 36 | |
37 | - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
37 | + } else if (typeof my != 'undefined') { | |
38 | 38 | AlipayBanner.I.show(); |
39 | - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
39 | + } else if (typeof wx !== 'undefined') { | |
40 | 40 | WxBanner.I.show(); |
41 | 41 | } |
42 | 42 | |
... | ... | @@ -45,11 +45,11 @@ export default class AdService { |
45 | 45 | * banner 隐藏 |
46 | 46 | */ |
47 | 47 | hideBanner() { |
48 | - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
48 | + if (typeof tt != 'undefined') { | |
49 | 49 | |
50 | - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
50 | + } else if (typeof my != 'undefined') { | |
51 | 51 | AlipayBanner.I.hide(); |
52 | - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
52 | + } else if (typeof wx !== 'undefined') { | |
53 | 53 | WxBanner.I.hide(); |
54 | 54 | } |
55 | 55 | } |
... | ... | @@ -58,11 +58,11 @@ export default class AdService { |
58 | 58 | */ |
59 | 59 | destoryBanner() { |
60 | 60 | |
61 | - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
61 | + if (typeof tt != 'undefined') { | |
62 | 62 | |
63 | - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
63 | + } else if (typeof my != 'undefined') { | |
64 | 64 | AlipayBanner.I.destory(); |
65 | - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
65 | + } else if (typeof wx !== 'undefined') { | |
66 | 66 | WxBanner.I.destory(); |
67 | 67 | } |
68 | 68 | } |
... | ... | @@ -72,11 +72,11 @@ export default class AdService { |
72 | 72 | * @param adUnitId |
73 | 73 | */ |
74 | 74 | initInterstitialAd(adUnitId?: string) { |
75 | - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
75 | + if (typeof tt != 'undefined') { | |
76 | 76 | // return DouyinInterstitial.initInterstitialAd(adUnitId); |
77 | - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
77 | + } else if (typeof my != 'undefined') { | |
78 | 78 | AlipayInterstitial.initInterstitialAd(adUnitId) |
79 | - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
79 | + } else if (typeof wx !== 'undefined') { | |
80 | 80 | return WxInterstitial.initInterstitialAd(adUnitId) |
81 | 81 | } |
82 | 82 | } |
... | ... | @@ -87,11 +87,11 @@ export default class AdService { |
87 | 87 | createInterstitialAd(adUnitId: string) { |
88 | 88 | console.log('~~~~~~~~~~~插屏'); |
89 | 89 | // return WxInterstitial.showInterstitialAd(adUnitId) |
90 | - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
90 | + if (typeof tt != 'undefined') { | |
91 | 91 | // return DouyinInterstitial.initInterstitialAd(adUnitId); |
92 | - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
92 | + } else if (typeof my != 'undefined') { | |
93 | 93 | AlipayInterstitial.showInterstitialAd(adUnitId) |
94 | - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
94 | + } else if (typeof wx !== 'undefined') { | |
95 | 95 | return WxInterstitial.showInterstitialAd(adUnitId) |
96 | 96 | } |
97 | 97 | } |
... | ... | @@ -130,10 +130,10 @@ export default class AdService { |
130 | 130 | let { id, appid, path, game } = data; |
131 | 131 | LogService.I.jumps(id, type); |
132 | 132 | if (!path) path = `?channel_id=${GAMEDATA.channel_id}`; |
133 | - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
134 | - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
133 | + if (typeof tt != 'undefined') { | |
134 | + } else if (typeof my != 'undefined') { | |
135 | 135 | return AlipayApi.I.navigateToMiniProgram(appid, path, opts) |
136 | - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
136 | + } else if (typeof wx !== 'undefined') { | |
137 | 137 | return WxApi.I.navigateToMiniProgram(appid, path, opts) |
138 | 138 | } |
139 | 139 | ... | ... |
wxsdk/share/SDKShare.ts
... | ... | @@ -55,10 +55,10 @@ export default class SDKShare { |
55 | 55 | LogService.I.share(shareKey, share_id, DOT_SHARE_TYPE.share) |
56 | 56 | } |
57 | 57 | // 主动拉起转发 |
58 | - if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
58 | + if (typeof my != 'undefined') { | |
59 | 59 | //模拟分享支付宝上面会失败 |
60 | 60 | return AlipayApi.I.shareAppMessage(commonObj, callbackObj) |
61 | - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
61 | + } else if (typeof wx !== 'undefined') { | |
62 | 62 | return wx.shareAppMessage(commonObj); |
63 | 63 | } else { |
64 | 64 | return callbackObj.success(); |
... | ... | @@ -83,7 +83,7 @@ export default class SDKShare { |
83 | 83 | forward(params: any, opts: any = {}) { |
84 | 84 | let me = this; |
85 | 85 | let { title, imageUrl, query, imageUrlId } = params; |
86 | - if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
86 | + if (typeof my != 'undefined') { | |
87 | 87 | my.onShareAppMessage = function () { |
88 | 88 | return { |
89 | 89 | title: title, | ... | ... |
wxsdk/share/SDKVideo.ts
... | ... | @@ -179,7 +179,7 @@ export default class SDKVideo { |
179 | 179 | try { |
180 | 180 | __LOG__ && console.warn("handleLoaded2"); |
181 | 181 | LogService.I.adStat(this.videoKey, this.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.show) |
182 | - if (cc.sys.platform === cc.sys.WECHAT_GAME && typeof qq == 'undefined') { | |
182 | + if (typeof wx !== 'undefined' && typeof qq == 'undefined') { | |
183 | 183 | if (that.videoAd.isReady()) {//抖音、qq 没有 isReady |
184 | 184 | that.show_time = Date.now(); |
185 | 185 | await that.videoAd.show(); | ... | ... |
wxsdk/wx/WxLogin.ts
... | ... | @@ -6,7 +6,6 @@ import WxSystem from "./WxSystem"; |
6 | 6 | import DateUtils from "../utils/DateUtils"; |
7 | 7 | import LogService from "../service/LogService"; |
8 | 8 | import { DOT_SHARE_TYPE } from "../base/SDKEnum"; |
9 | -import ShareVideoService from "../service/ShareVideoService"; | |
10 | 9 | import OnlineService from "../service/OnlineService"; |
11 | 10 | import AlipayApi from '../alipay/AlipayApi'; |
12 | 11 | |
... | ... | @@ -19,9 +18,7 @@ export default class WxLogin { |
19 | 18 | */ |
20 | 19 | async login(isAuthorize: boolean): Promise<any> { |
21 | 20 | |
22 | - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
23 | - return | |
24 | - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
21 | + if (typeof my !== 'undefined') { | |
25 | 22 | let self = this; |
26 | 23 | return new Promise(async (resolve, reject) => { |
27 | 24 | if (isAuthorize) { |
... | ... | @@ -36,7 +33,7 @@ export default class WxLogin { |
36 | 33 | self.weakLogin({ errCode: 1, msg: '默认未授权登录' }, code, resolve, reject) |
37 | 34 | } |
38 | 35 | }); |
39 | - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
36 | + } else if (typeof wx !== 'undefined') { | |
40 | 37 | return new Promise(async (resolve, reject) => { |
41 | 38 | let code = await WxApi.I.login(); |
42 | 39 | if (isAuthorize) { | ... | ... |