Commit 12e5925fadbbcddf789ef4fc6875ccaaaf959e23
1 parent
f76f173b
Exists in
zfb_waibu_linshi
and in
1 other branch
支付宝版本sdk
Showing
47 changed files
with
1478 additions
and
3052 deletions
Show diff stats
sdk/Analytics.ts
1 | -import TAMgr from "../../framework/ta/TAMgr"; | |
2 | -import { SDKLogLevel } from "../../framework/wxsdk/service/LogService"; | |
3 | -import WXSDK from "../../framework/wxsdk/WXSDK"; | |
4 | - | |
1 | +import { LogLevel } from "../wxsdk/service/LogService"; | |
2 | +import WXSDK from "../wxsdk/WXSDK"; | |
5 | 3 | |
6 | 4 | |
7 | 5 | export class Analytics { |
8 | 6 | private static _instance: Analytics; |
9 | - private systemType: number; | |
7 | + private systemType: number | |
10 | 8 | static get I(): Analytics { |
11 | 9 | return this._instance || (this._instance = new Analytics); |
12 | 10 | } |
... | ... | @@ -22,14 +20,8 @@ export class Analytics { |
22 | 20 | |
23 | 21 | // 游戏打点 |
24 | 22 | dot(dot_type: string, data: any = {}) { |
25 | - if (typeof wx == 'undefined'&&typeof my == 'undefined') { | |
26 | - console.log("dot", dot_type, data); | |
27 | - return | |
28 | - } | |
29 | - // 数数 | |
30 | - if (['receive_reward', 'button','merge_item','addToTempStore','talk','fund','mail','milktea','mail','activity_welcome','activity_raffle','activity_bp','piggy','invite','apple_tree','energy_cost','gem_cost','gold_cost','dress_cost','gem_output','gold_output','energy_output','exp_output','dress_output'].indexOf(dot_type) == -1) {// 排除部分key | |
31 | - TAMgr.Ins.dot(dot_type, data); | |
32 | - } | |
23 | + if (typeof my == 'undefined') return | |
24 | + // wx.aldSendEvent(dot_type, data); //阿拉丁打点,没需求注释即可 | |
33 | 25 | return WXSDK.stat.dot(dot_type, data); |
34 | 26 | } |
35 | 27 | |
... | ... | @@ -52,7 +44,9 @@ export class Analytics { |
52 | 44 | * @param stagename 关卡名称,格式:"xx模式-第x关" |
53 | 45 | * @param pattern 模式名称,格式:"xx模式" |
54 | 46 | */ |
55 | - levelStart(stageid, stagename, pattern) { | |
47 | + levelStart(stageid, stagename?, pattern?) { | |
48 | + if (!stagename) stagename = `第${stageid}关` | |
49 | + if (!pattern) pattern = '普通模式' | |
56 | 50 | return WXSDK.stat.levelStart(stageid, stagename, pattern) |
57 | 51 | } |
58 | 52 | /** |
... | ... | @@ -67,6 +61,8 @@ export class Analytics { |
67 | 61 | * @param params_desc 道具描述 |
68 | 62 | */ |
69 | 63 | levelRunning(stageid, stagename, pattern, event, params_id, params_name, params_count, params_desc?) { |
64 | + if (!stagename) stagename = `第${stageid}关` | |
65 | + if (!pattern) pattern = '普通模式' | |
70 | 66 | return WXSDK.stat.levelRunning(stageid, stagename, pattern, event, params_id, params_name, params_count, params_desc) |
71 | 67 | } |
72 | 68 | /** |
... | ... | @@ -78,8 +74,10 @@ export class Analytics { |
78 | 74 | * @param times 时间 |
79 | 75 | * @param perc 失败时的完成进度 (浮点数) |
80 | 76 | */ |
81 | - async levelEnd(stageid, stagename, pattern, event, times, perc?) { | |
82 | - return WXSDK.stat.levelEnd(stageid, stagename, pattern, event, times, perc) | |
77 | + async levelEnd(stageid, stagename, pattern, event, times, perc?, valence = 0) { | |
78 | + if (!stagename) stagename = `第${stageid}关` | |
79 | + if (!pattern) pattern = '普通模式' | |
80 | + return WXSDK.stat.levelEnd(stageid, stagename, pattern, event, times, perc,valence) | |
83 | 81 | } |
84 | 82 | |
85 | 83 | |
... | ... | @@ -90,7 +88,7 @@ export class Analytics { |
90 | 88 | * @param level 日志等级 |
91 | 89 | * @returns |
92 | 90 | */ |
93 | - clientLog(content, level = SDKLogLevel.debug) { | |
91 | + clientLog(content, level = LogLevel.debug) { | |
94 | 92 | return WXSDK.stat.clientLog(content, level) |
95 | 93 | } |
96 | 94 | /** |
... | ... | @@ -103,18 +101,14 @@ export class Analytics { |
103 | 101 | consume(id: number, typ: number, nums: number, gsne: string) { |
104 | 102 | return WXSDK.stat.consume(id, typ, nums, gsne) |
105 | 103 | } |
106 | - /** | |
107 | - * loading上报 | |
108 | - * @param typ 1开始加载、2加载进行中、3加载结束 | |
109 | - * @param stageid 加载id | |
110 | - * @param stagename 加载内容 | |
111 | - * @param event complete:成功 fail:失败 | |
112 | - * @param times 加载消耗时间 单位毫秒 | |
113 | - * @param perc 完成度 | |
114 | - */ | |
115 | - loading(typ: string, stageid: string, stagename: string, event: string, times: string, perc?: number) { | |
116 | - return WXSDK.stat.loading(typ, stageid, stagename, event, times, perc) | |
117 | - } | |
118 | 104 | |
119 | 105 | |
120 | -} | |
121 | 106 | \ No newline at end of file |
107 | +} | |
108 | +export enum EventKey { | |
109 | + toggleScene = 'toggleScene', | |
110 | + recoverGame = 'recoverGame', | |
111 | + replayGame = 'replayGame', | |
112 | + settingClose = 'settingClose', | |
113 | + updateLvUI = 'updateLvUI', | |
114 | + | |
115 | +} | ... | ... |
sdk/GameServicePlus.ts
... | ... | @@ -1,377 +0,0 @@ |
1 | -import DataService from "../../framework/wxsdk/service/DataService"; | |
2 | -import GameService from "../../framework/wxsdk/service/GameService"; | |
3 | -import WxPay from "../../framework/wxsdk/wx/WxPay"; | |
4 | -import SDKApiPlus from "./SDKApiPlus"; | |
5 | - | |
6 | - | |
7 | - | |
8 | -export default class GameServicePlus extends GameService { | |
9 | - memberSave(content: string, params: any = {}) { | |
10 | - return SDKApiPlus.memberSave({ uid: DataService.I.UserId, token: DataService.I.Token, content, ...params }); | |
11 | - } | |
12 | - | |
13 | - memberGet() { | |
14 | - return SDKApiPlus.memberGet({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
15 | - } | |
16 | - memberSesetAup() { | |
17 | - return SDKApiPlus.memberSesetAup({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
18 | - } | |
19 | - | |
20 | - memberClear() { | |
21 | - return SDKApiPlus.memberClear({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
22 | - } | |
23 | - | |
24 | - getGameNotice() { | |
25 | - return SDKApiPlus.notice(); | |
26 | - } | |
27 | - | |
28 | - mail() { | |
29 | - return SDKApiPlus.mail({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
30 | - } | |
31 | - | |
32 | - /** | |
33 | - * 改变邮件状态 | |
34 | - * @param id id为0或不传id时为 一键领取、一键删除 | |
35 | - * @param status 1已读 2领取 3删除。如同时修改多个状态格式:1,2 | |
36 | - * @returns | |
37 | - */ | |
38 | - updateMailStatus(id: number, status: string) { | |
39 | - return SDKApiPlus.mailStatus({ id, status, uid: DataService.I.UserId, token: DataService.I.Token }); | |
40 | - } | |
41 | - | |
42 | - getQRcode() { | |
43 | - return SDKApiPlus.QRcode(); | |
44 | - } | |
45 | - | |
46 | - convertCDkey(cdkey: string) { | |
47 | - return SDKApiPlus.cdkey({ uid: DataService.I.UserId, token: DataService.I.Token, cdkey: cdkey }); | |
48 | - } | |
49 | - | |
50 | - clearData() { | |
51 | - return SDKApiPlus.clearData({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
52 | - } | |
53 | - | |
54 | - goodsList() { | |
55 | - return SDKApiPlus.goodsList({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
56 | - } | |
57 | - | |
58 | - createOrder(goodid: string) { | |
59 | - return SDKApiPlus.createOrder({ uid: DataService.I.UserId, token: DataService.I.Token, goodid }); | |
60 | - } | |
61 | - | |
62 | - queryOrder(no: string) { | |
63 | - return SDKApiPlus.queryOrder({ uid: DataService.I.UserId, token: DataService.I.Token, no }); | |
64 | - } | |
65 | - | |
66 | - confirmOrder(no: string) { | |
67 | - return SDKApiPlus.confirmOrder({ uid: DataService.I.UserId, token: DataService.I.Token, no }); | |
68 | - } | |
69 | - | |
70 | - /** | |
71 | - * 支付 | |
72 | - * @param params | |
73 | - * @param opts | |
74 | - * @returns | |
75 | - */ | |
76 | - pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}) { | |
77 | - return WxPay.I.pay(params, opts); | |
78 | - } | |
79 | - /** | |
80 | - * 订单查询 | |
81 | - */ | |
82 | - orderQuery(source) { | |
83 | - return SDKApiPlus.orderQuery({ | |
84 | - ...this.buildParams(), | |
85 | - source | |
86 | - }); | |
87 | - } | |
88 | - /** | |
89 | - * 订单查询 | |
90 | - */ | |
91 | - preorder(goodid: string, orderid: string) { | |
92 | - return SDKApiPlus.preorder({ | |
93 | - ...this.buildParams2(), | |
94 | - token: DataService.I.Token, | |
95 | - goodid, orderid | |
96 | - }); | |
97 | - } | |
98 | - | |
99 | - /** | |
100 | - * 获取玩家历史存档 | |
101 | - * @param uid | |
102 | - * @param token | |
103 | - */ | |
104 | - getUserHistory(uid: string, token: string) { | |
105 | - return SDKApiPlus.getUserHistory({ uid: uid, token: token }); | |
106 | - } | |
107 | - | |
108 | - /** | |
109 | - * 获取玩家历史存档 | |
110 | - * @param data //需要包含uid,token | |
111 | - */ | |
112 | - saveUserHistory(data: any) { | |
113 | - return SDKApiPlus.saveUserHistory(data); | |
114 | - } | |
115 | - | |
116 | - /** | |
117 | - * 重置GM标识 | |
118 | - */ | |
119 | - setAup(typ: number = 0) { | |
120 | - return SDKApiPlus.setAup({ uid: DataService.I.UserId, token: DataService.I.Token, typ }); | |
121 | - } | |
122 | - | |
123 | - /** | |
124 | - * 获取分享图片 | |
125 | - * @param items 2,1,0|3,1,1|3,1,1|3,1,1|3,1,1格式:2,1,0(类型,id,领取状态)领取状态:1已领取0未领取 | |
126 | - * @param zoom 图片缩放比例 | |
127 | - * @returns | |
128 | - */ | |
129 | - getShareImage(items: string, zoom: number = 1) { | |
130 | - return SDKApiPlus.getShareImg({ uid: DataService.I.UserId, token: DataService.I.Token, items, zoom }); | |
131 | - } | |
132 | - | |
133 | - /** | |
134 | - * 获取我的今日分享 | |
135 | - * @param refresh 是否刷新 | |
136 | - */ | |
137 | - getShare(refresh?: number) { | |
138 | - let req = { uid: DataService.I.UserId, token: DataService.I.Token }; | |
139 | - if (refresh) { | |
140 | - req['refresh'] = refresh; | |
141 | - } | |
142 | - return SDKApiPlus.getShare(req); | |
143 | - } | |
144 | - | |
145 | - /** | |
146 | - * 获取好友分享详情 | |
147 | - * @param id 分享id | |
148 | - * @param date 分享日期 格式:20220524 | |
149 | - */ | |
150 | - getShareInfo(id: number, date: string) { | |
151 | - return SDKApiPlus.getShareInfo({ uid: DataService.I.UserId, token: DataService.I.Token, id, date }); | |
152 | - } | |
153 | - | |
154 | - /** | |
155 | - * 领取好友分享 | |
156 | - * @param id 分享id | |
157 | - * @param date 分享日期 格式:20220524 | |
158 | - * @param itemid 分享选项ID | |
159 | - */ | |
160 | - getShareReward(id: number, date: string, itemid: number) { | |
161 | - return SDKApiPlus.receiveShare({ uid: DataService.I.UserId, token: DataService.I.Token, id, date, itemid }); | |
162 | - } | |
163 | - | |
164 | - /** | |
165 | - * 领取额外进度奖励 | |
166 | - * @param id 分享id | |
167 | - * @param date 分享日期 格式:20220524 | |
168 | - */ | |
169 | - getProgressReward(id: number, date: string) { | |
170 | - return SDKApiPlus.getProgressReward({ uid: DataService.I.UserId, token: DataService.I.Token, id, date }); | |
171 | - } | |
172 | - | |
173 | - saveStory(key: string, data: string) { | |
174 | - // return SDKApiPlus.saveStory({ | |
175 | - // id: UserManager.I.curStory.id, | |
176 | - // lv: UserManager.I.curStory.lv, | |
177 | - // fbid: UserManager.I.curStory.fbid, | |
178 | - // fbindex: UserManager.I.curStory.fbindex, | |
179 | - // data, | |
180 | - // uid: DataService.I.UserId, | |
181 | - // token: DataService.I.Token, | |
182 | - // }); | |
183 | - } | |
184 | - | |
185 | - /** | |
186 | - * 我的邀请详情 | |
187 | - * @returns | |
188 | - */ | |
189 | - getInviteInfo() { | |
190 | - return SDKApiPlus.getInviteInfo({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
191 | - } | |
192 | - | |
193 | - /** | |
194 | - * 领取邀请奖励 | |
195 | - * @param id 挡位id | |
196 | - */ | |
197 | - receiveInvite(id: number) { | |
198 | - return SDKApiPlus.receiveInvite({ uid: DataService.I.UserId, token: DataService.I.Token, id }); | |
199 | - } | |
200 | - | |
201 | - /** | |
202 | - * 心跳 | |
203 | - */ | |
204 | - beatheart() { | |
205 | - return SDKApiPlus.heartbeat({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
206 | - } | |
207 | - /** | |
208 | - * 周卡/月卡列表 | |
209 | - */ | |
210 | - recCardList() { | |
211 | - return SDKApiPlus.recCardList({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
212 | - } | |
213 | - | |
214 | - /** | |
215 | - * 领取周卡/月卡奖励 | |
216 | - * @param typ 第几天 week周 month月 | |
217 | - */ | |
218 | - recCardReward(typ: string) { | |
219 | - return SDKApiPlus.recCardReward({ uid: DataService.I.UserId, token: DataService.I.Token, typ }); | |
220 | - } | |
221 | - | |
222 | - /** | |
223 | - * 领取基金列表 | |
224 | - */ | |
225 | - recGrowthList() { | |
226 | - return SDKApiPlus.recGrowthList({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
227 | - } | |
228 | - | |
229 | - /** | |
230 | - * 领取基金列表 | |
231 | - * @param goodid 购买的基金商品ID | |
232 | - * @param level 等级 | |
233 | - */ | |
234 | - recGrowthReward(goodid: string, level: number) { | |
235 | - return SDKApiPlus.recGrowthReward({ uid: DataService.I.UserId, token: DataService.I.Token, goodid, level }); | |
236 | - } | |
237 | - | |
238 | - /** | |
239 | - * 获取无尽礼包数据 | |
240 | - */ | |
241 | - recEndlessList(groupId: string) { | |
242 | - return SDKApiPlus.recEndlessList({ uid: DataService.I.UserId, token: DataService.I.Token, group_id: groupId }); | |
243 | - } | |
244 | - | |
245 | - /** | |
246 | - * 领取无尽礼包 | |
247 | - */ | |
248 | - recEndlessReward(groupId: string, id: string, date: string) { | |
249 | - return SDKApiPlus.recEndlessReward({ uid: DataService.I.UserId, token: DataService.I.Token, group_id: groupId, id, date }); | |
250 | - } | |
251 | - | |
252 | - /** | |
253 | - * 获取新手礼包数据 | |
254 | - */ | |
255 | - getNewbieGiftData() { | |
256 | - return SDKApiPlus.getNewbieGiftData({ uid: DataService.I.UserId, token: DataService.I.Token }); | |
257 | - } | |
258 | - | |
259 | - /** | |
260 | - * 领取新手礼包 | |
261 | - * @param days 第几天 | |
262 | - */ | |
263 | - recNewbieGift(days: string) { | |
264 | - return SDKApiPlus.recNewbieGift({ uid: DataService.I.UserId, token: DataService.I.Token, days }); | |
265 | - } | |
266 | - | |
267 | - | |
268 | - /** | |
269 | - * 订阅消息 | |
270 | - * @param tmplId 订阅ID | |
271 | - * @param message 订阅内容 | |
272 | - * @param sendtime 订阅发送时间s二选一参数 | |
273 | - * @param times 订阅延迟时间s二选一参数 | |
274 | - * @param status 1取消以前相同模板信息,默认为0不取消 | |
275 | - */ | |
276 | - async sendSubScribe(tmplId: string, message: string, sendtime: number, times: number = 0, status: number = 1) { | |
277 | - let uid = +DataService.I.UserId; | |
278 | - let token = DataService.I.Token + ''; | |
279 | - let openid = DataService.I.OpenId + ''; | |
280 | - | |
281 | - let data = { | |
282 | - uid, | |
283 | - token, | |
284 | - openid, | |
285 | - status, | |
286 | - message: encodeURIComponent(message), | |
287 | - temid: tmplId | |
288 | - }; | |
289 | - if (times) { | |
290 | - data["times"] = times; | |
291 | - } else { | |
292 | - data["sendtime"] = Math.floor(sendtime); | |
293 | - } | |
294 | - let back = await SDKApiPlus.sendsubscribe(data) | |
295 | - return back; | |
296 | - } | |
297 | - | |
298 | - | |
299 | - /** | |
300 | - * 取消订阅消息 | |
301 | - * @param tmplId 订阅ID | |
302 | - */ | |
303 | - async cancelSubscribe(tmplId: string) { | |
304 | - let uid = +DataService.I.UserId; | |
305 | - let token = DataService.I.Token + ''; | |
306 | - let openid = DataService.I.OpenId + ''; | |
307 | - | |
308 | - let data = { | |
309 | - uid, | |
310 | - token, | |
311 | - openid, | |
312 | - temid: tmplId | |
313 | - }; | |
314 | - let back = await SDKApiPlus.cancelSubscribe(data) | |
315 | - return back; | |
316 | - } | |
317 | - /** | |
318 | - * 自定义活动 | |
319 | - * @param id 活动ID(后台的ID) | |
320 | - */ | |
321 | - activityCustom(id?: string) { | |
322 | - return SDKApiPlus.activityCustom({ id }); | |
323 | - } | |
324 | - | |
325 | - /** | |
326 | - * 添加排行榜 | |
327 | - * @param typ 游戏端自定义排行标识 | |
328 | - * @param fraction 分数 如果上报的分数小于以前上报的分数,则不会更新 | |
329 | - * @param rankData 扩展字段 | |
330 | - * @returns | |
331 | - */ | |
332 | - rankAddV2(typ: string, fraction: number, rankData?: string) { | |
333 | - return SDKApiPlus.rankAddV2({ typ, fraction, rankData, uid: DataService.I.UserId, token: DataService.I.Token }); | |
334 | - } | |
335 | - /** | |
336 | - * 排行榜列表 | |
337 | - * @param percent percent等于1 的时候会返回排行榜总人数和自己的当前排名 | |
338 | - */ | |
339 | - rankListV2(typ: string, percent: number = 0) { | |
340 | - return SDKApiPlus.rankListV2({ typ, percent, uid: DataService.I.UserId, token: DataService.I.Token }); | |
341 | - } | |
342 | - /** | |
343 | - * 活动排行榜配置 | |
344 | - * @param name 游戏端自定义排行标识 | |
345 | - */ | |
346 | - activityRankConfig(name: string) { | |
347 | - return SDKApiPlus.activityRankConfig({ name, uid: DataService.I.UserId, token: DataService.I.Token }); | |
348 | - } | |
349 | - /** | |
350 | - * 活动排行榜添加分数 | |
351 | - * @param name 游戏端自定义排行标识 | |
352 | - * @param score 分数 | |
353 | - * @param extend 扩展 | |
354 | - */ | |
355 | - activityRankAdd(name: string, score: number, extend: string) { | |
356 | - return SDKApiPlus.activityRankAdd({ name, score, extend, uid: DataService.I.UserId, token: DataService.I.Token }); | |
357 | - } | |
358 | - /** | |
359 | - * 活动排行榜 | |
360 | - * @param name 游戏端自定义排行标识 | |
361 | - */ | |
362 | - activityRankList(name: string) { | |
363 | - return SDKApiPlus.activityRankList({ name, uid: DataService.I.UserId, token: DataService.I.Token }); | |
364 | - } | |
365 | - /** | |
366 | - * 活动排行榜奖励 | |
367 | - * @param name 游戏端自定义排行标识 | |
368 | - */ | |
369 | - activityRankReward(name: string) { | |
370 | - return SDKApiPlus.activityRankReward({ name, uid: DataService.I.UserId, token: DataService.I.Token }); | |
371 | - } | |
372 | - | |
373 | - static instance: GameServicePlus; | |
374 | - static get I(): GameServicePlus { | |
375 | - return this.instance || (this.instance = new GameServicePlus()); | |
376 | - } | |
377 | -} | |
378 | 0 | \ No newline at end of file |
sdk/Ge.ts
... | ... | @@ -1,50 +0,0 @@ |
1 | -import { sys } from "cc"; | |
2 | -import { GAMEDATA } from "../../framework/wxsdk/base/SDKConst"; | |
3 | -import { SDKToolsPlus } from "./SDKToolsPlus"; | |
4 | - | |
5 | - | |
6 | - | |
7 | -export class Ge { | |
8 | - private static _instance: GravityAnalyticsAPI; | |
9 | - static get I(): GravityAnalyticsAPI { | |
10 | - return this._instance; | |
11 | - } | |
12 | - constructor() { | |
13 | - } | |
14 | - | |
15 | - public static init() { | |
16 | - // console.log("ge初始化") | |
17 | - const config = { | |
18 | - accessToken: "ihcpiWLHTqDs5oZEGsnyxCrFXBaSeoju", // 项目通行证,在:网站后台-->管理中心-->应用列表中找到Access Token列 复制(首次使用可能需要先新增应用) | |
19 | - clientId: SDKToolsPlus.openId, // 用户唯一标识,如微信小程序的openid | |
20 | - autoTrack: { | |
21 | - appLaunch: true, // 自动采集 $MPLaunch | |
22 | - appShow: true, // 自动采集 $MPShow | |
23 | - appHide: true, // 自动采集 $MPHide | |
24 | - }, | |
25 | - name: "ge", // 全局变量名称 | |
26 | - // debugMode: "debug", // 是否开启测试模式,开启测试模式后,可以在 网站后台--管理中心--元数据--事件流中查看实时数据上报结果。(测试时使用,上线之后一定要关掉,改成none或者删除) | |
27 | - }; | |
28 | - let ge = new GravityAnalyticsAPI(config); | |
29 | - ge.init(); | |
30 | - let isFirst = sys.localStorage.getItem('tt_register'); | |
31 | - if (!isFirst) { | |
32 | - // 首次注册 | |
33 | - let arr = GAMEDATA.version.split("."); | |
34 | - let version = +(arr[0] + arr[1] + arr[2]); | |
35 | - ge.register({ | |
36 | - name: SDKToolsPlus.uid, | |
37 | - version, | |
38 | - wx_openid: SDKToolsPlus.openId, | |
39 | - wx_unionid: "", | |
40 | - }).then((success) => { | |
41 | - // console.log("注册成功", success); | |
42 | - sys.localStorage.setItem('tt_register', "1") | |
43 | - }).catch((fail) => { | |
44 | - // console.error("注册失败", fail) | |
45 | - }) | |
46 | - } | |
47 | - this._instance = ge; | |
48 | - } | |
49 | - | |
50 | -} | |
51 | 0 | \ No newline at end of file |
sdk/SDKApiPlus.ts
... | ... | @@ -1,144 +0,0 @@ |
1 | -import { SDKApi } from "../../framework/wxsdk/http/SDKApi"; | |
2 | -import DataService from "../../framework/wxsdk/service/DataService"; | |
3 | -import SDKHttpPlus from "./SDKHttpPlus"; | |
4 | - | |
5 | -export default class SDKApiPlus extends SDKApi { | |
6 | - //公告 | |
7 | - public static notice = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.notice, ...args); | |
8 | - //订阅 | |
9 | - public static sendsubscribe = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.sendsubscribe, ...args); | |
10 | - //取消订阅 | |
11 | - public static cancelSubscribe = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.cancelSubscribe, ...args); | |
12 | - //邮件 | |
13 | - public static mail = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.mail, ...args); | |
14 | - //邮件状态修改 | |
15 | - public static mailStatus = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.mailStatus, ...args); | |
16 | - //群二维码 | |
17 | - public static QRcode = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.QRcode, ...args); | |
18 | - //兑换码 | |
19 | - public static cdkey = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.cdkey, ...args); | |
20 | - //删除存档 | |
21 | - public static clearData = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.clearData, ...args); | |
22 | - //商品列表 | |
23 | - public static goodsList = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.goodsList, ...args); | |
24 | - //生成订单 | |
25 | - public static createOrder = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.createOrder, ...args); | |
26 | - //查询订单 | |
27 | - public static queryOrder = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.queryOrder, ...args); | |
28 | - //确认订单 | |
29 | - public static confirmOrder = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.confirmOrder, ...args); | |
30 | - //重置GM标识 | |
31 | - public static setAup = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.setAup, ...args); | |
32 | - //获取分享图片 | |
33 | - public static getShareImg = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getShareImg, ...args); | |
34 | - //获取今日分享 | |
35 | - public static getShare = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getShare, ...args); | |
36 | - //获取分享信息 | |
37 | - public static getShareInfo = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getShreInfo, ...args); | |
38 | - //领取好友分享 | |
39 | - public static receiveShare = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.receiveShare, ...args); | |
40 | - //领取分享额外奖励 | |
41 | - public static getProgressReward = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getProgressReward, ...args); | |
42 | - //保存副本 | |
43 | - public static saveStory = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.saveStory, ...args); | |
44 | - //我的邀请详情 | |
45 | - public static getInviteInfo = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getInviteInfo, ...args); | |
46 | - //领取邀请奖励 | |
47 | - public static receiveInvite = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.receiveInvite, ...args); | |
48 | - | |
49 | - // 保存用户数据 | |
50 | - public static memberSave = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.memberSave, ...args); | |
51 | - // 获取用户数据 | |
52 | - public static memberGet = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.memberGet, ...args); | |
53 | - // 重置修改标识 | |
54 | - public static memberSesetAup = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.memberSesetAup, ...args); | |
55 | - // 清除用户数据 | |
56 | - public static memberClear = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.memberClear, ...args); | |
57 | - //心跳 | |
58 | - public static heartbeat = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.memberXT, ...args); | |
59 | - //自定义活动 | |
60 | - public static activityCustom = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.activityCustom, ...args); | |
61 | - public static rankAddV2 = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.rankAddV2, ...args); | |
62 | - public static rankListV2 = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.rankListV2, ...args); | |
63 | - | |
64 | - //周卡/月卡列表 | |
65 | - public static recCardList = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recCardList, ...args); | |
66 | - //领取周卡/月卡奖励 | |
67 | - public static recCardReward = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recCardReward, ...args); | |
68 | - //领取基金列表 | |
69 | - public static recGrowthList = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recGrowthList, ...args); | |
70 | - //领取基金奖励 | |
71 | - public static recGrowthReward = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recGrowthReward, ...args); | |
72 | - //获取无尽礼包数据 | |
73 | - public static recEndlessList = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recEndlessList, ...args); | |
74 | - //领取无尽礼包 | |
75 | - public static recEndlessReward = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recEndlessReward, ...args); | |
76 | - //获取新手礼包数据 | |
77 | - public static getNewbieGiftData = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getNewbieGiftData, ...args); | |
78 | - //领取新手礼包 | |
79 | - public static recNewbieGift = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recNewbieGift, ...args); | |
80 | - | |
81 | - // 活动排行榜相关 | |
82 | - public static activityRankConfig = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.activityRankConfig, ...args); | |
83 | - public static activityRankAdd = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.activityRankAdd, ...args); | |
84 | - public static activityRankList = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.activityRankList, ...args); | |
85 | - public static activityRankReward = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.activityRankReward, ...args); | |
86 | - | |
87 | - //后台 | |
88 | - public static getUserHistory = (...args) => SDKHttpPlus.backPost(DataService.I.GMApi, HostKeysPlus.getUserHistory, ...args); | |
89 | - public static saveUserHistory = (...args) => SDKHttpPlus.backPost(DataService.I.GMApi, HostKeysPlus.saveUserHistory, ...args); | |
90 | -} | |
91 | - | |
92 | - | |
93 | -export const HostKeysPlus = { | |
94 | - sendsubscribe: 'api/subscribe/event', //订阅 | |
95 | - cancelSubscribe: 'api/subscribe/event/cancel', //取消订阅 | |
96 | - notice: 'mods/notice/list', //公告 | |
97 | - mail: 'mods/mail/list', //邮件 | |
98 | - mailStatus: '/mods/mail/status/u', //修改邮件状态 | |
99 | - QRcode: 'game/merge/system', //群二维码 | |
100 | - cdkey: 'game/merge/cdkey', //兑换CDkey | |
101 | - clearData: 'game/merge/clear', //删除存档 | |
102 | - goodsList: 'game/merge/goodslist', //商品列表 | |
103 | - createOrder: 'game/merge/order/create', //生成订单 | |
104 | - queryOrder: 'game/merge/order/query', //查询订单 | |
105 | - confirmOrder: 'game/merge/order/give', //确认订单 | |
106 | - setAup: 'game/merge/aup', //重置GM标识 | |
107 | - getShareImg: 'game/merge/share/getimg', //分享图片 | |
108 | - getShare: 'game/merge/share/get', //获取今日分享(自己的) | |
109 | - getShreInfo: 'game/merge/share/info', //获取分享详情(别人的) | |
110 | - receiveShare: 'game/merge/share/receive', //领取分享奖励 | |
111 | - getProgressReward: 'game/merge/share/reward/progress', //获取分享奖励 | |
112 | - saveStory: 'game/merge/cp/save', //保存副本 | |
113 | - getInviteInfo: 'api/member/invite/info', //获取邀请信息 | |
114 | - receiveInvite: 'api/member/invite/receive', //领取邀请奖励 | |
115 | - | |
116 | - memberSave: 'yueliangdao/member/save', //存用户数据 | |
117 | - memberGet: 'yueliangdao/member/get', //取用户数据 | |
118 | - memberSesetAup: 'yueliangdao/member/reset/aup', //重置修改标识 | |
119 | - memberClear: '3ad7e4ab92ae2249/member/clear', //清除用户数据 4.11改 | |
120 | - memberXT: 'yueliangdao/member/xt', //心跳 | |
121 | - activityCustom: 'mods/activity/custom', //自定义活动 | |
122 | - rankListV2: 'mods/rank/permanent/list', //排行榜2023-4-24 | |
123 | - rankAddV2: 'mods/rank/permanent/add', //更新排行榜2023-4-24 | |
124 | - | |
125 | - | |
126 | - recCardList: '3ad7e4ab92ae2249/member/ship/info', //周卡/月卡列表 | |
127 | - recCardReward: '3ad7e4ab92ae2249/member/ship/draw', //领取周卡/月卡奖励 | |
128 | - recGrowthList: 'game/merge/growth/list', //领取基金列表 | |
129 | - recGrowthReward: 'game/merge/growth/rec', //领取基金奖励 | |
130 | - recEndlessList: '3ad7e4ab92ae2249/egift/show', //获取无尽礼包数据 | |
131 | - recEndlessReward: '3ad7e4ab92ae2249/egift/draw', //领取无尽礼包 | |
132 | - getNewbieGiftData: '3ad7e4ab92ae2249/novice/list', //获取新手礼包数据 | |
133 | - recNewbieGift: '3ad7e4ab92ae2249/novice/draw', //领取新手礼包 | |
134 | - | |
135 | - activityRankConfig: 'yueliangdao/activities/rank/config', //活动排行榜配置 | |
136 | - activityRankAdd: 'yueliangdao/activities/rank/add', //活动排行榜添加分数 | |
137 | - activityRankList: 'yueliangdao/activities/rank/top', //活动排行榜 | |
138 | - activityRankReward: 'yueliangdao/activities/rank/draw', //活动排行榜奖励 | |
139 | - | |
140 | - | |
141 | - //后台 | |
142 | - getUserHistory: 'index/merge/history.html', //获取用户历史存档 | |
143 | - saveUserHistory: 'index/merge/setdata.html', //覆盖用户数据 | |
144 | -} |
sdk/SDKHttpPlus.ts
... | ... | @@ -1,139 +0,0 @@ |
1 | -import { DEBUG } from "cc/env"; | |
2 | -import { GAMEDATA, sdkEnv } from "../../framework/wxsdk/base/SDKConst"; | |
3 | -import SDKHttp from "../../framework/wxsdk/http/SDKHttp"; | |
4 | -import { WxHelper } from "./WxHelper"; | |
5 | -import LogService from "../../framework/wxsdk/service/LogService"; | |
6 | -import DataService from "../../framework/wxsdk/service/DataService"; | |
7 | - | |
8 | -sdkEnv.isDebug = DEBUG; | |
9 | -export default class SDKHttpPlus extends SDKHttp { | |
10 | - | |
11 | - public static async backRequest(url: string, method: string, data?: any, dataType: "json" | "string" = "json") { | |
12 | - return new Promise<IResult<any>>((resolve, reject) => { | |
13 | - data = { | |
14 | - ...data, | |
15 | - gameid: GAMEDATA.game_id, | |
16 | - } | |
17 | - | |
18 | - if (data && typeof data === "object") { | |
19 | - data = JSON.stringify(data); | |
20 | - } | |
21 | - data = data || ""; | |
22 | - if (method == "GET" && data != "") { | |
23 | - data = JSON.parse(data); | |
24 | - let str = '' | |
25 | - for (let key in data) { | |
26 | - str = str + `${key}` + '=' + `${data[key]}&` | |
27 | - } | |
28 | - url += "?" + str; | |
29 | - data = ""; | |
30 | - } | |
31 | - // let info = "[url:" + url + ", data:" + data + "]"; | |
32 | - // console.error("info", info) | |
33 | - let xhr = new XMLHttpRequest(); | |
34 | - xhr.onreadystatechange = function () { | |
35 | - if (xhr.readyState == 4) { | |
36 | - if (xhr.status >= 200 && xhr.status < 400) { | |
37 | - let responseText: any = xhr.responseText; | |
38 | - // cc.log("responseText", responseText) | |
39 | - try { | |
40 | - responseText = JSON.parse(responseText); | |
41 | - // cc.log("responseText22", responseText) | |
42 | - if (url.indexOf('.json') > -1) { | |
43 | - resolve({ code: 0, data: responseText, msg: responseText.msg }); | |
44 | - } else { | |
45 | - resolve({ code: +responseText.code, data: responseText.data, msg: responseText.msg }); | |
46 | - } | |
47 | - return | |
48 | - } catch (ex) { | |
49 | - // console.error("httpRequest[parseError]:responseText=" + xhr.responseText); | |
50 | - resolve({ msg: "JSON parse error:" + ex.message, code: -1 }); | |
51 | - return; | |
52 | - } | |
53 | - } else { | |
54 | - console.error(xhr.status, '网络请求失败!'); | |
55 | - resolve({ code: -2 }); | |
56 | - } | |
57 | - } | |
58 | - }; | |
59 | - | |
60 | - xhr.ontimeout = function (info): void { | |
61 | - console.error("info1", info) | |
62 | - resolve({ msg: `请求超时!`, code: -3 }); | |
63 | - } | |
64 | - xhr.onerror = function (info): void { | |
65 | - console.error("info2", info) | |
66 | - resolve({ msg: `请求失败!`, code: -4 }); | |
67 | - } | |
68 | - xhr.onabort = function (info): void { | |
69 | - console.error("info3", info) | |
70 | - resolve({ msg: `请求关闭!`, code: -5 }); | |
71 | - } | |
72 | - | |
73 | - xhr.timeout = 30000; | |
74 | - xhr.open(method, url, true); | |
75 | - | |
76 | - if (method == "POST") { | |
77 | - xhr.setRequestHeader("Content-Type", "application/json;charset=utf-8")//application/x-www-form-urlencoded | |
78 | - // if (cc.sys.os === 'Android') { | |
79 | - // cc.error("http__uid", AppSdkData.I.uid); | |
80 | - // xhr.setRequestHeader('Uuid', `${AppSdkData.I.uid}`); | |
81 | - // } else { | |
82 | - // xhr.setRequestHeader('Uuid', `909`); | |
83 | - // } | |
84 | - | |
85 | - } | |
86 | - console.log("data", data) | |
87 | - xhr.send(data); | |
88 | - }); | |
89 | - } | |
90 | - | |
91 | - public static async backGet(baseUrl: string, url: string, data?: any, dataType: "json" | "string" = "json") { | |
92 | - if (this.withMock(url)) { | |
93 | - return this.mockData(url); | |
94 | - } | |
95 | - | |
96 | - url = baseUrl + url; | |
97 | - return this.backRequest(url, "GET", data, dataType); | |
98 | - } | |
99 | - | |
100 | - public static backPost(baseUrl: string, url: string, data?: any, dataType: "json" | "string" = "json") { | |
101 | - if (this.withMock(url)) { | |
102 | - return this.mockData(url); | |
103 | - } | |
104 | - | |
105 | - url = baseUrl + url; | |
106 | - return this.backRequest(url, "POST", data, dataType); | |
107 | - } | |
108 | -} | |
109 | - | |
110 | -SDKHttp.onErrorResponse = async function (data: any) { | |
111 | - console.log("onErrorResponse", data) | |
112 | - if (data.code > 0) { | |
113 | - LogService.I.dot("errCode", { form: data.code + "_" + DataService.I?.Data?.userId }) | |
114 | - } else { | |
115 | - LogService.I.dot("errCode", { form: data.code }) | |
116 | - } | |
117 | - if (data.code == 1008) { | |
118 | - let ret = await WxHelper.showModal({ | |
119 | - title: '登录验证失败,请重新登录', | |
120 | - content: data.msg, | |
121 | - showCancel: false, | |
122 | - confirmText: '重启' | |
123 | - }) | |
124 | - if (ret) { | |
125 | - WxHelper.restartMiniProgram(); | |
126 | - } | |
127 | - } | |
128 | - if (data.code == 1011000) { | |
129 | - let ret = await WxHelper.showModal({ | |
130 | - title: '数据被修改', | |
131 | - content: data.msg, | |
132 | - showCancel: false, | |
133 | - confirmText: '重启' | |
134 | - }) | |
135 | - if (ret) { | |
136 | - WxHelper.restartMiniProgram(); | |
137 | - } | |
138 | - } | |
139 | -}; | |
140 | 0 | \ No newline at end of file |
sdk/SDKTools.ts
1 | -import { GAMEDATA } from "../../framework/wxsdk/base/SDKConst"; | |
2 | -import DateUtils from "../../framework/wxsdk/utils/DateUtils"; | |
3 | -import WXSDK from "../../framework/wxsdk/WXSDK"; | |
4 | - | |
1 | +import AlipayApi from "../wxsdk/alipay/AlipayApi"; | |
2 | +import { GAMEDATA } from "../wxsdk/base/SDKConst"; | |
3 | +import DateUtils from "../wxsdk/utils/DateUtils"; | |
4 | +import WXSDK from "../wxsdk/WXSDK"; | |
5 | 5 | |
6 | 6 | /* |
7 | 7 | * SDK工具类库; |
8 | 8 | */ |
9 | 9 | export class SDKTools { |
10 | 10 | static get isWx() { |
11 | - return typeof wx !== 'undefined'; | |
12 | - } | |
13 | - static get isZfb() { | |
14 | 11 | return typeof my !== 'undefined'; |
15 | 12 | } |
16 | 13 | static get isSupported() { |
... | ... | @@ -83,8 +80,10 @@ export class SDKTools { |
83 | 80 | * isOff:是否关闭默认显示banner |
84 | 81 | * } |
85 | 82 | */ |
86 | - static createBanner(adUnitId: string = GAMEDATA.bannerId, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean ,isCreate?:boolean}) { | |
83 | + static createBanner(adUnitId: string = GAMEDATA.bannerId, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { | |
87 | 84 | if (!this.isWx) return |
85 | + // if (SDKUtils.compareVersion(my.env.clientVersion, '10.3.66') < 0) return; | |
86 | + // console.log('banner') | |
88 | 87 | return WXSDK.ad.createBanner(adUnitId, opts); |
89 | 88 | } |
90 | 89 | /** |
... | ... | @@ -114,6 +113,7 @@ export class SDKTools { |
114 | 113 | * 插屏 |
115 | 114 | */ |
116 | 115 | static createInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { |
116 | + // console.log('~~~~~~~~~~chaping') | |
117 | 117 | if (!this.isWx) return Promise.resolve({ code: 1, msg: "暂无广告" }) |
118 | 118 | return WXSDK.ad.createInterstitialAd(adUnitId); |
119 | 119 | } |
... | ... | @@ -167,9 +167,12 @@ export class SDKTools { |
167 | 167 | /** |
168 | 168 | * 订阅 |
169 | 169 | * @param template_ids 模板id eg['aaaaaaa','bbbbbbb'] |
170 | - * @param success 成功回调 | |
171 | - * @param fail 失败回调 | |
170 | + * @param ids 对应后台的id eg:['1','2'] | |
172 | 171 | */ |
172 | + // static subScribe(template_ids: Array<string>, ids: Array<string>) { | |
173 | + // if (!this.isWx) return | |
174 | + // return WXSDK.game.subScribe(template_ids, ids) | |
175 | + // } | |
173 | 176 | static subScribe(template_ids: Array<string>, success: Function, fail: Function) { |
174 | 177 | if (!window['wx']) return; |
175 | 178 | return WXSDK.game.subScribe(template_ids, success, fail); |
... | ... | @@ -247,16 +250,7 @@ export class SDKTools { |
247 | 250 | |
248 | 251 | |
249 | 252 | |
250 | - /** | |
251 | - * 互动数据解密 | |
252 | - * @param iv | |
253 | - * @param encryptedData | |
254 | - * @returns | |
255 | - */ | |
256 | - static wxencrypted(iv, encryptedData): Promise<IResult<any>> { | |
257 | - if (!this.isWx) return Promise.resolve({ code: -1 }) | |
258 | - return WXSDK.game.wxencrypted(iv, encryptedData); | |
259 | - } | |
253 | + | |
260 | 254 | /** |
261 | 255 | * 互导数据 |
262 | 256 | * 1抽屉广告2猜你喜欢3格子广告4试玩 |
... | ... | @@ -301,7 +295,7 @@ export class SDKTools { |
301 | 295 | * @returns |
302 | 296 | */ |
303 | 297 | static pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}) { |
304 | - return WXSDK.game.pay(params, opts); | |
298 | + return WXSDK.game.pay(params, opts) | |
305 | 299 | } |
306 | 300 | /** |
307 | 301 | * 检测支付是否成功 |
... | ... | @@ -342,26 +336,21 @@ export class SDKTools { |
342 | 336 | return WXSDK.game.behavior() |
343 | 337 | } |
344 | 338 | |
345 | - /** | |
346 | - * | |
347 | - * scene 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)(必填) | |
348 | - content 需检测的文本内容,文本字数的上限为2500字(必填) | |
349 | - nickname 用户昵称(非必填) | |
350 | - title 文本标题(非必填) | |
351 | - signature 个性签名,该参数仅在资料类场景有效(scene=1)(非必填) | |
352 | - */ | |
353 | - static checkmsg(scene: number, content: string, nickname?: string, title?: string, signature?: string) { | |
354 | - return WXSDK.game.checkmsg(scene, content, nickname, title, signature) | |
355 | - } | |
339 | + //阿里增量任务 | |
340 | + static incrementGameaction(action_code, success: Function, fail: Function) { | |
341 | + if (this.uid) { | |
342 | + AlipayApi.I.incrementGameaction(action_code).then((res) => { | |
343 | + success(); | |
344 | + }).catch((res) => { | |
345 | + fail && fail(); | |
346 | + }); | |
347 | + } else { | |
348 | + //登录状态过期,重进登录 | |
349 | + fail(); | |
350 | + } | |
356 | 351 | |
357 | - /** | |
358 | - * 修改用户头像昵称 | |
359 | - */ | |
360 | - static updateNickname(nickname: string, headurl: string) { | |
361 | - return WXSDK.game.updateNickname(nickname, headurl) | |
362 | 352 | } |
363 | 353 | |
364 | - | |
365 | 354 | } |
366 | 355 | |
367 | 356 | /** | ... | ... |
sdk/SDKToolsPlus.ts
... | ... | @@ -1,420 +0,0 @@ |
1 | -import { sys } from "cc"; | |
2 | -import { EventCenter } from "../../framework/core/utils/EventCenter"; | |
3 | -import { EnvCode } from "../../framework/wxsdk/base/SDKEnum"; | |
4 | -import DataService from "../../framework/wxsdk/service/DataService"; | |
5 | -import { GameEvent } from "../../game/const/GameEvent"; | |
6 | -import GameServicePlus from "./GameServicePlus"; | |
7 | -import { SDKTools } from "./SDKTools"; | |
8 | - | |
9 | -export class ServerError { | |
10 | - private static _errors = { | |
11 | - "0": { msg: "成功", desc: "接口调用成功" }, | |
12 | - "1000": { msg: "操作失败", desc: "检查Hermes后台配置是否正确" }, | |
13 | - "1001": { msg: "未知错误", desc: "联系开发人员排查错误" }, | |
14 | - "1002": { msg: "参数错误", desc: "请参照接口文档对比参数和参数类型是否正确" }, | |
15 | - "1003": { msg: "签名错误", desc: "检查appkey跟后台是否对应" }, | |
16 | - "1004": { msg: "数据不存在", desc: "查询的数据不存在等" }, | |
17 | - "1005": { msg: "解析参数失败,请检查参数合法性", desc: "参数中是否有危险字符,比如SQL注入等" }, | |
18 | - "4500": { msg: "商品不存在", desc: "检查Hermes后台配置是否正确" }, | |
19 | - "4501": { msg: "订单未支付", desc: "" }, | |
20 | - "4502": { msg: "不能重复发放", desc: "" }, | |
21 | - "4503": { msg: "兑换码不存在", desc: " " }, | |
22 | - "4504": { msg: "兑换码不在有效期内", desc: " " }, | |
23 | - "4505": { msg: "兑换码已失效", desc: " " }, | |
24 | - "4506": { msg: "iv error", desc: "防止用户本地修改数据" }, | |
25 | - "4507": { msg: "数据被修改", desc: "用户数据被GM工具修改,需重新登录重置" }, | |
26 | - "4508": { msg: "此商品已达到最大购买限制", desc: "限购" }, | |
27 | - "4509": { msg: "没有上传文件", desc: "检查文件name属性是否正确" }, | |
28 | - "4510": { msg: "文件超出最大限制", desc: "最大1M" }, | |
29 | - "4511": { msg: "请先授权获取微信头像信息", desc: "登录接口获取" }, | |
30 | - "4513": { msg: "没有达到刷新条件", desc: "生成过一次且没有领取 才可刷新" }, | |
31 | - "4514": { msg: "刷新次数超限", desc: "刷新次数达到 配置最大项" }, | |
32 | - "4515": { msg: "分享失效", desc: "跨天失效等" }, | |
33 | - "4516": { msg: "分享不存在", desc: "分享ID不存在等" }, | |
34 | - "4517": { msg: "已被领取", desc: "被其他人领取" }, | |
35 | - "4518": { msg: "今日领取次数超限", desc: "今天领取的次数达到配置最大项" }, | |
36 | - "4519": { msg: "已领过其他选项", desc: "只能领取一个" }, | |
37 | - "4520": { msg: "没有达到领取条件", desc: "领取进度是否完成" }, | |
38 | - "4522": { msg: "只能领取自己的奖励", desc: "" }, | |
39 | - "1009": { msg: "您的账号已因数据异常而被封禁,如需申诉可以向微信客服反馈。", desc: "" }, | |
40 | - "3004": { msg: "活动已经结束", desc: "" }, | |
41 | - } | |
42 | - | |
43 | - private static _unknownError = { msg: "未知错误", desc: "联系开发人员排查错误" }; | |
44 | - static getError(code: string): { msg: string, desc: string } { | |
45 | - return this._errors[code] || this._unknownError; | |
46 | - } | |
47 | - | |
48 | - static this(key: string): string { | |
49 | - return (this._errors[key] || this._unknownError).msg; | |
50 | - } | |
51 | -} | |
52 | - | |
53 | -/* | |
54 | -* SDK工具类库; | |
55 | -*/ | |
56 | -export class SDKToolsPlus extends SDKTools { | |
57 | - static get isTT() { | |
58 | - return sys.platform == sys.Platform.BYTEDANCE_MINI_GAME; | |
59 | - } | |
60 | - | |
61 | - //提交订单 | |
62 | - static doPreorder(data, goodid: string, price: number, orderid: string) { | |
63 | - if (!data.code && data.data) { | |
64 | - let { config, paytype } = data.data; | |
65 | - // goodid = goodid + ""; | |
66 | - // console.log("支付方式"+paytype); | |
67 | - switch (paytype) { | |
68 | - case "1"://H5 客服消息支付,游戏内调用发片消息接口 sendMessagePath:path | |
69 | - var { img, title, path } = config; | |
70 | - wx.openCustomerServiceConversation({ | |
71 | - showMessageCard: true, //是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息 | |
72 | - sendMessageTitle: title ? title : '我要充值!',//会话内消息卡片标题 | |
73 | - sendMessagePath: path,//会话内消息卡片路径//channel=${SDKTools.ChannelId}&item=10&uid=${SDKTools.UserId} | |
74 | - sendMessageImg: img ? img : 'https://wxsdk-cdn.miso-lab.com/moon-island/share/fx_chongzhi.jpg',//会话内消息卡片图片路径 | |
75 | - success: (ret) => { | |
76 | - //记录状态 | |
77 | - //onshow检测状态,判断是否充值成功 | |
78 | - console.log("支付成功:", ret); | |
79 | - EventCenter.I.emit(GameEvent.PAY_POLLING, true); | |
80 | - }, | |
81 | - fail: (ret) => { | |
82 | - console.log("fail", ret); | |
83 | - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); | |
84 | - } | |
85 | - }) | |
86 | - break; | |
87 | - case "2": | |
88 | - | |
89 | - | |
90 | - break; | |
91 | - case "3"://米大师支付,游戏支付成功需要调用米大师订单上报接口 | |
92 | - var { payid } = config; | |
93 | - SDKTools.pay({ payid, goodid, money: price, orderid: orderid }).then(res => { | |
94 | - if (!res.code) { | |
95 | - console.log("支付成功", res); | |
96 | - EventCenter.I.emit(GameEvent.PAY_CONFIRM, orderid, goodid); | |
97 | - } else { | |
98 | - console.log("支付失败", res); | |
99 | - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); | |
100 | - } | |
101 | - }).catch(err => { | |
102 | - console.log("支付失败2:", err); | |
103 | - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); | |
104 | - }) | |
105 | - break; | |
106 | - case "4"://跳转小程序支付,游戏直接跳转返回的小程序路径 | |
107 | - var { appid, page } = config; | |
108 | - wx.navigateToMiniProgram({ | |
109 | - appId: appid, | |
110 | - path: page, | |
111 | - envVersion: DataService.I.EnvEnum === EnvCode.Prod ? 'release' : "trial",//opts.envVersion || 'release', | |
112 | - success(res: any) { | |
113 | - console.log("成功:", res) | |
114 | - // resolve(res); | |
115 | - EventCenter.I.emit(GameEvent.PAY_POLLING, true); | |
116 | - }, | |
117 | - fail(err: any) { | |
118 | - console.log("失败", err) | |
119 | - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); | |
120 | - // reject(err); | |
121 | - } | |
122 | - }); | |
123 | - break; | |
124 | - case "5"://扫码小程序支付,imgurl为二维码地址,提示用户扫码即可 | |
125 | - EventCenter.I.emit(GameEvent.PAY_POLLING, true); | |
126 | - var { imgurl } = config; | |
127 | - wx.previewImage({ | |
128 | - current: imgurl, // 当前显示图片的http链接 | |
129 | - urls: [imgurl] // 需要预览的图片http链接列表 | |
130 | - }) | |
131 | - | |
132 | - break; | |
133 | - case "6"://二维码支付,windows下需要调用扫码支付接口 | |
134 | - EventCenter.I.emit(GameEvent.PAY_POLLING, true); | |
135 | - var { qrcode } = config; | |
136 | - wx.previewImage({ | |
137 | - current: qrcode, // 当前显示图片的http链接 | |
138 | - urls: [qrcode] // 需要预览的图片http链接列表 | |
139 | - }) | |
140 | - | |
141 | - break; | |
142 | - case "7"://抖音支付 | |
143 | - var { payid } = config; | |
144 | - SDKTools.pay({ payid, goodid, money: price, orderid: orderid }).then(res => { | |
145 | - if (!res.code) { | |
146 | - console.log("支付成功", res); | |
147 | - EventCenter.I.emit(GameEvent.PAY_CONFIRM, orderid, goodid); | |
148 | - } else { | |
149 | - console.log("支付失败", res); | |
150 | - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); | |
151 | - } | |
152 | - }).catch(err => { | |
153 | - console.log("支付失败", err); | |
154 | - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); | |
155 | - }) | |
156 | - break; | |
157 | - case "10"://支付宝支付 | |
158 | - var { payid } = config; | |
159 | - SDKTools.pay({ payid, goodid, money: price, orderid: orderid }).then(res => { | |
160 | - if (!res.code) { | |
161 | - console.log("111tttttt"+Date.now()); | |
162 | - EventCenter.I.emit(GameEvent.PAY_POLLING_NOW, true); | |
163 | - } else { | |
164 | - console.log("支付失败", JSON.stringify(res)); | |
165 | - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); | |
166 | - } | |
167 | - }).catch(err => { | |
168 | - console.log("支付失败", JSON.stringify(err)); | |
169 | - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); | |
170 | - }) | |
171 | - break; | |
172 | - default: | |
173 | - // utils.tips("出错!") | |
174 | - break; | |
175 | - } | |
176 | - } else { | |
177 | - // utils.tips("出错!") | |
178 | - } | |
179 | - } | |
180 | - | |
181 | - /** | |
182 | - * 获取群二维码 | |
183 | - */ | |
184 | - static QRcode() { | |
185 | - return GameServicePlus.I.getQRcode(); | |
186 | - } | |
187 | - | |
188 | - /** | |
189 | - * 兑换CDK | |
190 | - */ | |
191 | - static convertCDkey(cdkey: string) { | |
192 | - return GameServicePlus.I.convertCDkey(cdkey); | |
193 | - } | |
194 | - | |
195 | - /** | |
196 | - * 商品列表 | |
197 | - */ | |
198 | - static goodsList() { | |
199 | - return GameServicePlus.I.goodsList(); | |
200 | - } | |
201 | - | |
202 | - /** | |
203 | - * 生成订单 | |
204 | - */ | |
205 | - static createOrder(goodid: string) { | |
206 | - return GameServicePlus.I.createOrder(goodid); | |
207 | - } | |
208 | - | |
209 | - /** | |
210 | - * 查询订单 | |
211 | - */ | |
212 | - static queryOrder(no: string) { | |
213 | - return GameServicePlus.I.queryOrder(no); | |
214 | - } | |
215 | - | |
216 | - /** | |
217 | - * 确认订单 | |
218 | - */ | |
219 | - static confirmOrder(no: string) { | |
220 | - return GameServicePlus.I.confirmOrder(no); | |
221 | - } | |
222 | - | |
223 | - /** | |
224 | - * 获取玩家历史存档 | |
225 | - */ | |
226 | - static getUserHistory(uid: string, token: string) { | |
227 | - return GameServicePlus.I.getUserHistory(uid, token); | |
228 | - } | |
229 | - | |
230 | - /** | |
231 | - * 获取玩家历史存档 | |
232 | - * @param data //需要包含uid,token | |
233 | - */ | |
234 | - static saveUserHistory(data: any) { | |
235 | - return GameServicePlus.I.saveUserHistory(data); | |
236 | - } | |
237 | - | |
238 | - /** | |
239 | - * 重置GM标识 | |
240 | - */ | |
241 | - static setAup(typ: number = 0) { | |
242 | - return GameServicePlus.I.setAup(typ); | |
243 | - } | |
244 | - | |
245 | - /** | |
246 | - * 获取分享图片 | |
247 | - * @param items 2,1,0|3,1,1|3,1,1|3,1,1|3,1,1格式:2,1,0(类型,id,领取状态)领取状态:1已领取0未领取 | |
248 | - * @param zoom 图片缩放比例 | |
249 | - * @returns | |
250 | - */ | |
251 | - static getShareImage(items: string, zoom = 1) { | |
252 | - return GameServicePlus.I.getShareImage(items, zoom); | |
253 | - } | |
254 | - | |
255 | - /** | |
256 | - * 获取今日分享 | |
257 | - * @param refresh 是否刷新 | |
258 | - */ | |
259 | - static getShare(refresh?: number) { | |
260 | - return GameServicePlus.I.getShare(refresh); | |
261 | - } | |
262 | - | |
263 | - /** | |
264 | - * 获取分享详情 | |
265 | - * @param id 分享id | |
266 | - * @param date 分享日期 格式:20220524 | |
267 | - */ | |
268 | - static getShareInfo(id: number, date: string) { | |
269 | - if (typeof id === "string") { | |
270 | - id = parseInt(id); | |
271 | - } | |
272 | - return GameServicePlus.I.getShareInfo(id, date); | |
273 | - } | |
274 | - | |
275 | - /** | |
276 | - * 领取好友分享 | |
277 | - * @param id 分享id | |
278 | - * @param date 分享日期 格式:20220524 | |
279 | - * @param itemid 分享选项ID | |
280 | - */ | |
281 | - static getShareReward(id: number, date: string, itemid: number) { | |
282 | - if (typeof id === "string") { | |
283 | - id = parseInt(id); | |
284 | - } | |
285 | - return GameServicePlus.I.getShareReward(id, date, itemid); | |
286 | - } | |
287 | - | |
288 | - /** | |
289 | - * 领取额外进度奖励 | |
290 | - * @param id 分享id | |
291 | - * @param date 分享日期 格式:20220524 | |
292 | - */ | |
293 | - static getProgressReward(id: number, date: string) { | |
294 | - if (typeof id === "string") { | |
295 | - id = parseInt(id); | |
296 | - } | |
297 | - return GameServicePlus.I.getProgressReward(id, date); | |
298 | - } | |
299 | - | |
300 | - static getInviteInfo() { | |
301 | - return GameServicePlus.I.getInviteInfo(); | |
302 | - } | |
303 | - | |
304 | - static receiveInvite(id: number) { | |
305 | - return GameServicePlus.I.receiveInvite(id); | |
306 | - } | |
307 | - | |
308 | - static heartbeat() { | |
309 | - return GameServicePlus.I.beatheart(); | |
310 | - } | |
311 | - | |
312 | - /** | |
313 | - * 领取列表 | |
314 | - * @param status 类型1周卡2月卡 | |
315 | - */ | |
316 | - static recCardList() { | |
317 | - return GameServicePlus.I.recCardList(); | |
318 | - } | |
319 | - | |
320 | - /** | |
321 | - * 领取列表 | |
322 | - * @param typ 第几天 week周 month月 | |
323 | - */ | |
324 | - static recCardReward(typ: string) { | |
325 | - return GameServicePlus.I.recCardReward(typ); | |
326 | - } | |
327 | - | |
328 | - /** | |
329 | - * 领取基金列表 | |
330 | - */ | |
331 | - static recGrowthList() { | |
332 | - return GameServicePlus.I.recGrowthList(); | |
333 | - } | |
334 | - | |
335 | - /** | |
336 | - * 领取基金列表 | |
337 | - * @param goodid 购买的基金商品ID | |
338 | - * @param level 等级 | |
339 | - */ | |
340 | - static recGrowthReward(goodid: string, level: number) { | |
341 | - return GameServicePlus.I.recGrowthReward(goodid, level); | |
342 | - } | |
343 | - | |
344 | - /** | |
345 | - * 获取无尽礼包数据 | |
346 | - */ | |
347 | - static recEndlessList(groupId: string) { | |
348 | - return GameServicePlus.I.recEndlessList(groupId); | |
349 | - } | |
350 | - | |
351 | - /** | |
352 | - * 领取无尽礼包 | |
353 | - * @param date 当前日期 | |
354 | - */ | |
355 | - static recEndlessReward(groupId: string, id: string, date: string) { | |
356 | - return GameServicePlus.I.recEndlessReward(groupId, id, date); | |
357 | - } | |
358 | - | |
359 | - /** | |
360 | - * 获取新手礼包数据 | |
361 | - */ | |
362 | - static getNewbieGiftData() { | |
363 | - return GameServicePlus.I.getNewbieGiftData(); | |
364 | - } | |
365 | - | |
366 | - /** | |
367 | - * 领取新手礼包 | |
368 | - * @param days 当前天 | |
369 | - */ | |
370 | - static recNewbieGift(days: string) { | |
371 | - return GameServicePlus.I.recNewbieGift(days); | |
372 | - } | |
373 | - | |
374 | - | |
375 | - /** | |
376 | - * 订阅消息 | |
377 | - * @param tmplId 订阅ID | |
378 | - * @param message 订阅内容 | |
379 | - * @param sendtime 订阅发送时间s二选一参数 | |
380 | - * @param times 订阅延迟时间s二选一参数 | |
381 | - * @param status 1取消以前相同模板信息,默认为0不取消 | |
382 | - */ | |
383 | - static async sendSubScribe(tmplId: string, message: string, sendtime: number, times: number = 0, status = 1) { | |
384 | - return GameServicePlus.I.sendSubScribe(tmplId, message, sendtime, times, status); | |
385 | - } | |
386 | - | |
387 | - /** | |
388 | - * 取消订阅消息 | |
389 | - * @param tmplId 订阅ID | |
390 | - */ | |
391 | - static async cancelSubscribe(tmplId: string) { | |
392 | - return GameServicePlus.I.cancelSubscribe(tmplId); | |
393 | - } | |
394 | - /** | |
395 | - * 自定义活动 | |
396 | - * @param id 活动ID(后台的ID) | |
397 | - */ | |
398 | - static activityCustom(id?: string) { | |
399 | - return GameServicePlus.I.activityCustom(id); | |
400 | - } | |
401 | - /** | |
402 | - * 添加排行榜 | |
403 | - * @param typ 游戏端自定义排行标识 | |
404 | - * @param fraction 分数 如果上报的分数小于以前上报的分数,则不会更新 | |
405 | - * @param rankData 扩展字段 | |
406 | - * @returns | |
407 | - */ | |
408 | - static rankAddV2(typ: string, fraction: number, rankData?: string) { | |
409 | - return GameServicePlus.I.rankAddV2(typ, fraction, rankData); | |
410 | - } | |
411 | - /** | |
412 | - * 排行榜列表 | |
413 | - * @param typ 游戏端自定义排行标识 | |
414 | - * @param percent percent等于1 的时候会返回排行榜总人数和自己的当前排名 | |
415 | - */ | |
416 | - static rankListV2(typ: string, percent: number = 0) { | |
417 | - return GameServicePlus.I.rankListV2(typ, percent); | |
418 | - } | |
419 | - | |
420 | -} | |
421 | 0 | \ No newline at end of file |
sdk/WxHelper.ts
1 | 1 | |
2 | 2 | // import UserManager from "../manager/UserManager"; |
3 | 3 | |
4 | -import { Node, UITransform, game, view } from "cc"; | |
5 | -import { ALIPAY } from "cc/env"; | |
4 | +import DataService from "../wxsdk/service/DataService"; | |
5 | +import AlipayApi from "../wxsdk/alipay/AlipayApi"; | |
6 | +import { SDKTools } from "./SDKTools"; | |
6 | 7 | |
7 | 8 | /** WXapi */ |
8 | 9 | export class WxHelper { |
... | ... | @@ -12,19 +13,19 @@ export class WxHelper { |
12 | 13 | |
13 | 14 | /** 微信用户信息 */ |
14 | 15 | public static userInfo: WxUserInfo; |
15 | - static get isWx() { | |
16 | - return typeof wx !== 'undefined'; | |
16 | + public static get isOperable() { | |
17 | + return (cc.sys.platform === cc.sys.WECHAT_GAME || cc.sys.platform === cc.sys.ALIPAY_GAME) | |
17 | 18 | } |
18 | 19 | |
19 | 20 | /** 获取设备信息 */ |
20 | 21 | public static getSystemInfo() { |
21 | - if (this.isWx) this.SystemInfo = wx.getSystemInfoSync(); | |
22 | + if (typeof my !== 'undefined') this.SystemInfo = my.getSystemInfoSync(); | |
22 | 23 | } |
23 | 24 | |
24 | 25 | /** 像开放数据域发送信息 */ |
25 | 26 | public static postMessage(eventType: string, data?: any): void { |
26 | - if (!this.isWx || !this.checkVerison('1.9.92')) return; | |
27 | - wx.getOpenDataContext().postMessage({ | |
27 | + if (typeof my === 'undefined' || !this.checkVerison('1.9.92')) return; | |
28 | + my.getOpenDataContext().postMessage({ | |
28 | 29 | eventType: eventType, |
29 | 30 | data: data |
30 | 31 | }); |
... | ... | @@ -32,17 +33,15 @@ export class WxHelper { |
32 | 33 | } |
33 | 34 | |
34 | 35 | /** 更新微信开放数据榜单数据 */ |
35 | - public static updateWxRank(key: string, value: number) { | |
36 | - if (typeof my != 'undefined') { | |
37 | - return; | |
38 | - } | |
39 | - if (!this.isWx || !this.checkVerison('1.9.92')) return; | |
36 | + public static updateWxRank(score: number) { | |
37 | + | |
38 | + if (typeof wx === 'undefined' || !this.checkVerison('1.9.92')) return; | |
40 | 39 | let data = { |
41 | - value, | |
40 | + score: score | |
42 | 41 | } |
43 | 42 | wx.setUserCloudStorage({ |
44 | 43 | KVDataList: [{ |
45 | - key, | |
44 | + key: 'score', | |
46 | 45 | value: JSON.stringify(data) |
47 | 46 | }] |
48 | 47 | }) |
... | ... | @@ -50,10 +49,10 @@ export class WxHelper { |
50 | 49 | } |
51 | 50 | |
52 | 51 | /** 创建用户反馈按钮 */ |
53 | - public static createFeedbackButton(target: Node) { | |
52 | + public static createFeedbackButton(target: cc.Node) { | |
54 | 53 | |
55 | 54 | let data = this.computWxPosition(target); |
56 | - return wx.createFeedbackButton({ | |
55 | + return my.createFeedbackButton({ | |
57 | 56 | type: 'text', |
58 | 57 | text: ' ', |
59 | 58 | style: { |
... | ... | @@ -72,10 +71,10 @@ export class WxHelper { |
72 | 71 | /** 获取用户信息按钮 */ |
73 | 72 | public static userInfoButton: any; |
74 | 73 | /** 创建一个获取用户信息按钮 */ |
75 | - public static createUserInfoButton(target: Node) { | |
74 | + public static createUserInfoButton(target: cc.Node) { | |
76 | 75 | let data = this.computWxPosition(target); |
77 | 76 | // console.log("data", data) |
78 | - return wx.createUserInfoButton({ | |
77 | + return my.createUserInfoButton({ | |
79 | 78 | type: 'text', |
80 | 79 | text: ' ', |
81 | 80 | style: { |
... | ... | @@ -96,36 +95,33 @@ export class WxHelper { |
96 | 95 | } |
97 | 96 | |
98 | 97 | /** 计算微信坐标 */ |
99 | - public static computWxPosition(target: Node): { left: number, top: number, width: number, height: number } { | |
98 | + public static computWxPosition(target: cc.Node): { left: number, top: number, width: number, height: number } { | |
100 | 99 | |
101 | 100 | let data = { left: 0, top: 0, width: 0, height: 0 } |
102 | - let pos = target.worldPosition; | |
103 | - let width = target.getComponent(UITransform).width; | |
104 | - let height = target.getComponent(UITransform).height; | |
105 | - let ratio = view.getDevicePixelRatio(); | |
106 | - let scale = view.getScaleX(); | |
101 | + let rect = target.getBoundingBoxToWorld(); | |
102 | + let ratio = cc.view.getDevicePixelRatio(); | |
103 | + let scale = cc.view.getScaleX(); | |
107 | 104 | let factor = scale / ratio; |
108 | - // let point = cc.v2(rect.x, rect.y); | |
105 | + // let point = v2(rect.x, rect.y); | |
109 | 106 | // point.mulSelf(scale); |
110 | - data.left = (pos.x - width / 2) * factor; | |
111 | - data.top = wx.getSystemInfoSync().screenHeight - (pos.y + height / 2) * factor; | |
112 | - data.width = width * factor; | |
113 | - data.height = height * factor; | |
114 | - | |
115 | - // let btnSize = cc.size(target.width + 10, target.height + 10); | |
116 | - // let frameSize = cc.view.getFrameSize(); | |
117 | - // let winSize = cc.director.getWinSize(); | |
118 | - // // cc.log("winSize: ",winSize); | |
119 | - // // cc.log("frameSize: ",frameSize); | |
107 | + data.left = rect.x * factor; | |
108 | + data.top = this.SystemInfo.screenHeight - (rect.y + rect.height) * factor; | |
109 | + data.width = rect.width * factor; | |
110 | + data.height = rect.height * factor; | |
111 | + | |
112 | + // let btnSize = size(target.width + 10, target.height + 10); | |
113 | + // let frameSize = view.getFrameSize(); | |
114 | + // let winSize = director.getWinSize(); | |
115 | + // // log("winSize: ",winSize); | |
116 | + // // log("frameSize: ",frameSize); | |
120 | 117 | // //适配不同机型来创建微信按钮 |
121 | 118 | // data.left = (winSize.width * 0.5 + target.x - btnSize.width * 0.5) / winSize.width * frameSize.width; |
122 | 119 | // data.top = (winSize.height * 0.5 - target.y - btnSize.height * 0.5) / winSize.height * frameSize.height; |
123 | 120 | // data.width = btnSize.width / winSize.width * frameSize.width; |
124 | 121 | // data.height = btnSize.height / winSize.height * frameSize.height; |
125 | - // cc.log("button pos: ",cc.v2(left,top)); | |
126 | - // cc.log("button size: ",cc.size(width,height)); | |
122 | + // log("button pos: ",v2(left,top)); | |
123 | + // log("button size: ",size(width,height)); | |
127 | 124 | |
128 | - // cc.log(data) | |
129 | 125 | return data; |
130 | 126 | |
131 | 127 | } |
... | ... | @@ -165,30 +161,10 @@ export class WxHelper { |
165 | 161 | |
166 | 162 | /** 显示一个对话框 */ |
167 | 163 | public static showModal(data: ShowModalType) { |
168 | - if (typeof my != 'undefined') { | |
169 | - return new Promise((resolve, reject) => { | |
170 | - wx.confirm({ | |
171 | - ...data, | |
172 | - success: (res: { confirm: boolean, cancel: boolean }) => { | |
173 | - if (res.confirm) { | |
174 | - resolve(true); | |
175 | - } else { | |
176 | - resolve(false); | |
177 | - } | |
178 | - }, | |
179 | - fail: () => { | |
180 | - reject(); | |
181 | - } | |
182 | - | |
183 | - }); | |
184 | - | |
185 | - }); | |
186 | - } | |
187 | - | |
188 | 164 | return new Promise((resolve, reject) => { |
189 | 165 | |
190 | - if (typeof wx !== 'undefined') { | |
191 | - wx.showModal({ | |
166 | + if (typeof my !== 'undefined') { | |
167 | + my.showModal({ | |
192 | 168 | ...data, |
193 | 169 | success: (res: { confirm: boolean, cancel: boolean }) => { |
194 | 170 | if (res.confirm) { |
... | ... | @@ -203,7 +179,6 @@ export class WxHelper { |
203 | 179 | |
204 | 180 | }); |
205 | 181 | } else { |
206 | - console.log(JSON.stringify(data)); | |
207 | 182 | } |
208 | 183 | |
209 | 184 | }); |
... | ... | @@ -216,41 +191,30 @@ export class WxHelper { |
216 | 191 | * @param time 关闭时间 |
217 | 192 | */ |
218 | 193 | public static showToast(msg: string, time: number = 1500) { |
219 | - if (!this.isWx) return; | |
220 | - if (typeof my != 'undefined') { | |
194 | + if (cc.sys.platform === cc.sys.WECHAT_GAME) | |
195 | + wx.showToast({ | |
196 | + title: msg, | |
197 | + icon: 'none', | |
198 | + duration: time | |
199 | + }) | |
200 | + else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
221 | 201 | my.showToast({ |
222 | 202 | type: 'none', |
223 | 203 | content: msg, |
224 | 204 | duration: time, |
225 | 205 | }); |
226 | - return; | |
206 | + } else { | |
207 | + console.log(msg) | |
227 | 208 | } |
228 | - wx.showToast({ | |
229 | - title: msg, | |
230 | - icon: 'none', | |
231 | - duration: time | |
232 | - }) | |
233 | 209 | |
234 | 210 | } |
235 | 211 | |
236 | 212 | /** 设置系统剪贴板的内容 */ |
237 | 213 | public static copy(str: string) { |
238 | 214 | if (!this.checkVerison('1.1.0')) return Promise.reject(''); |
239 | - if (typeof my != 'undefined') { | |
240 | - return new Promise((resolve, reject) => { | |
241 | - wx.setClipboard({ | |
242 | - text: str, | |
243 | - success: (res: any) => { | |
244 | - resolve(res); | |
245 | - }, | |
246 | - fail: () => { | |
247 | - resolve(''); | |
248 | - } | |
249 | - }); | |
250 | - }); | |
251 | - } | |
215 | + | |
252 | 216 | return new Promise((resolve, reject) => { |
253 | - wx.setClipboardData({ | |
217 | + my.setClipboardData({ | |
254 | 218 | data: str, |
255 | 219 | success: (res: any) => { |
256 | 220 | resolve(res); |
... | ... | @@ -264,10 +228,10 @@ export class WxHelper { |
264 | 228 | |
265 | 229 | /** 手机发生较长时间的振动(400 ms) */ |
266 | 230 | public static vibrateLong() { |
267 | - if (!this.checkVerison('1.2.0')) return Promise.reject(null); | |
231 | + // if (!this.checkVerison('1.2.0')) return Promise.reject(null); | |
268 | 232 | |
269 | 233 | return new Promise((resolve, reject) => { |
270 | - wx.vibrateLong({ | |
234 | + my.vibrateLong({ | |
271 | 235 | success: () => { |
272 | 236 | resolve(1); |
273 | 237 | }, |
... | ... | @@ -280,10 +244,10 @@ export class WxHelper { |
280 | 244 | |
281 | 245 | /** 手机发生较短时间的振动(15 ms) */ |
282 | 246 | public static vibrateShort() { |
283 | - if (!this.checkVerison('1.2.0')) return Promise.reject(null); | |
247 | + // if (!this.checkVerison('1.2.0')) return Promise.reject(null); | |
284 | 248 | |
285 | 249 | return new Promise<IResult<any>>((resolve, reject) => { |
286 | - wx.vibrateShort({ | |
250 | + my.vibrateShort({ | |
287 | 251 | success: () => { |
288 | 252 | resolve({ code: 0 }); |
289 | 253 | }, |
... | ... | @@ -299,13 +263,13 @@ export class WxHelper { |
299 | 263 | */ |
300 | 264 | public static checkUpdate(bol: boolean = true) { |
301 | 265 | if (!this.checkVerison('1.9.90')) return; |
302 | - const updateManager = wx.getUpdateManager(); | |
266 | + const updateManager = my.getUpdateManager(); | |
303 | 267 | updateManager.onCheckForUpdate(function (res) { |
304 | 268 | console.log('updateManager', res.hasUpdate); |
305 | 269 | }); |
306 | 270 | |
307 | 271 | updateManager.onUpdateReady(function () { |
308 | - wx.showModal({ | |
272 | + my.showModal({ | |
309 | 273 | title: '更新提示', |
310 | 274 | content: '新版本已经准备好,请重启应用!', |
311 | 275 | showCancel: bol, |
... | ... | @@ -326,7 +290,7 @@ export class WxHelper { |
326 | 290 | |
327 | 291 | return new Promise<IResult<any>>((resolve, reject) => { |
328 | 292 | if (!this.checkVerison('2.0.3')) resolve({ code: 1 }); |
329 | - wx.openCustomerServiceConversation({ | |
293 | + my.openCustomerServiceConversation({ | |
330 | 294 | showMessageCard: true, |
331 | 295 | sendMessageTitle: '我要更多好玩!', |
332 | 296 | sendMessageImg: 'http://dep.miso-lab.com/tetrischangeskin/bin/share/concat.png', |
... | ... | @@ -346,7 +310,7 @@ export class WxHelper { |
346 | 310 | |
347 | 311 | return new Promise<IResult<any>>((resolve, reject) => { |
348 | 312 | if (!this.checkVerison('2.0.3')) resolve({ code: 1 }); |
349 | - wx.openCustomerServiceConversation({ | |
313 | + my.openCustomerServiceConversation({ | |
350 | 314 | success: () => { |
351 | 315 | resolve({ code: 0 }); |
352 | 316 | }, |
... | ... | @@ -360,10 +324,10 @@ export class WxHelper { |
360 | 324 | |
361 | 325 | /** 回到前台 */ |
362 | 326 | public static onShow(callback: () => void) { |
363 | - if (!this.isWx) return; | |
364 | - wx.onShow(callback); | |
327 | + if (typeof my === 'undefined') return; | |
328 | + my.onShow(callback); | |
365 | 329 | // return new Promise<IResult<any>>((resolve, reject) => { |
366 | - // wx.onShow((res: any) => { | |
330 | + // my.onShow((res: any) => { | |
367 | 331 | // resolve({ code: 1 }); |
368 | 332 | // }); |
369 | 333 | // }); |
... | ... | @@ -373,14 +337,14 @@ export class WxHelper { |
373 | 337 | /** 切换到后台 */ |
374 | 338 | public static onHide(callback: () => void) { |
375 | 339 | |
376 | - if (!this.isWx) return; | |
377 | - wx.onHide(callback); | |
340 | + if (typeof my === 'undefined') return; | |
341 | + my.onHide(callback); | |
378 | 342 | |
379 | 343 | } |
380 | 344 | |
381 | 345 | public static updateShareMenu(value) { |
382 | - if (!this.isWx) return; | |
383 | - wx.updateShareMenu({ | |
346 | + if (typeof my === 'undefined') return; | |
347 | + my.updateShareMenu({ | |
384 | 348 | withShareTicket: value |
385 | 349 | }); |
386 | 350 | } |
... | ... | @@ -388,49 +352,18 @@ export class WxHelper { |
388 | 352 | /** |
389 | 353 | * 检查授权 |
390 | 354 | */ |
391 | - public static getSetting(scope: string = 'scope.userInfo') { | |
392 | - if (!this.isWx) return Promise.resolve(1); | |
393 | - return new Promise((resolve, reject) => { | |
394 | - wx.getSetting({ | |
395 | - success(res) { | |
396 | - if (res.authSetting[scope]) { | |
397 | - resolve(1) | |
398 | - } else { | |
399 | - reject() | |
400 | - } | |
401 | - } | |
402 | - }) | |
403 | - }) | |
404 | - } | |
405 | - /** | |
406 | - * 打开授权设置 | |
407 | - */ | |
408 | - public static openSetting(scope: string = 'scope.userInfo') { | |
409 | - if (!this.isWx) return Promise.resolve(1); | |
410 | - return new Promise((resolve, reject) => { | |
411 | - wx.openSetting({ | |
412 | - success(res) { | |
413 | - if (res.authSetting[scope]) { | |
414 | - resolve(1) | |
415 | - } else { | |
416 | - reject() | |
417 | - } | |
418 | - } | |
419 | - }) | |
420 | - }) | |
421 | - } | |
422 | - /** | |
423 | - * 打开授权窗口 | |
424 | - */ | |
425 | 355 | public static authorize(scope: string = 'scope.userInfo') { |
426 | - if (!this.isWx) return; | |
427 | - wx.authorize({ | |
428 | - scope: scope, | |
429 | - success(suc) { | |
430 | - console.log("suc", suc) | |
431 | - }, | |
432 | - fail(err) { | |
433 | - console.log("err", err) | |
356 | + if (typeof my === 'undefined') return; | |
357 | + my.getSetting({ | |
358 | + success(res) { | |
359 | + if (!res.authSetting[scope]) { | |
360 | + my.authorize({ | |
361 | + scope: scope, | |
362 | + success() { | |
363 | + | |
364 | + } | |
365 | + }) | |
366 | + } | |
434 | 367 | } |
435 | 368 | }) |
436 | 369 | } |
... | ... | @@ -438,42 +371,21 @@ export class WxHelper { |
438 | 371 | * 获取用户信息 |
439 | 372 | */ |
440 | 373 | public static getUserInfo(callback) { |
441 | - wx.getUserInfo({ | |
442 | - success: function (res) { | |
443 | - // console.log(res) | |
444 | - callback(res) | |
445 | - }, | |
446 | - fail: function (err) { | |
447 | - callback(err) | |
448 | - } | |
449 | - }) | |
450 | - } | |
451 | - /** | |
452 | - * 获取用户信息 自动弹出 | |
453 | - */ | |
454 | - public static getUserProfile(callback) { | |
455 | - if (!this.isWx) { | |
456 | - callback({ userInfo: "" }) | |
457 | - return | |
458 | - }; | |
459 | - wx.getUserProfile({ | |
460 | - desc: '补充用户资料', | |
374 | + my.getUserInfo({ | |
461 | 375 | success: function (res) { |
462 | 376 | // console.log(res) |
463 | 377 | callback(res) |
464 | 378 | }, |
465 | 379 | fail: function (err) { |
466 | - console.log("获取用户信息", err); | |
467 | 380 | callback(err) |
468 | 381 | } |
469 | 382 | }) |
470 | 383 | } |
471 | 384 | /** 游戏圈 */ |
472 | - public static createGameClubButton(target: Node) { | |
385 | + public static createGameClubButton(target: cc.Node) { | |
473 | 386 | let data = this.computWxPosition(target); |
474 | - //@ts-ignore | |
475 | - return wx.createGameClubButton({ | |
476 | - icon: 'white', | |
387 | + return my.createGameClubButton({ | |
388 | + icon: 'green', | |
477 | 389 | style: { |
478 | 390 | left: data.left, |
479 | 391 | top: data.top, |
... | ... | @@ -484,51 +396,65 @@ export class WxHelper { |
484 | 396 | |
485 | 397 | } |
486 | 398 | |
487 | - /** 抖音创建客服按钮 */ | |
488 | - public static createContactButton(target: Node) { | |
489 | - | |
490 | - let data = this.computWxPosition(target); | |
491 | - return wx.createContactButton({ | |
492 | - type: "text", // image | text | |
493 | - // image: "../resources/prefab/loading/mask", | |
494 | - text: ' ', | |
495 | - style: { | |
496 | - left: data.left, | |
497 | - top: data.top, | |
498 | - width: data.width, | |
499 | - height: data.height, | |
500 | - // lineHeight: 40, | |
501 | - backgroundColor: "#00000000", | |
502 | - // textAlign: "center", | |
503 | - // fontSize: 16, | |
504 | - // borderRadius: 5, | |
505 | - borderColor: "#00000000", | |
506 | - // borderWidth: 1, | |
507 | - // textColor: "#ffffff", | |
508 | - }, | |
509 | - success(res) { | |
510 | - console.log("createContactButton success", res); | |
511 | - }, | |
512 | - fail(res) { | |
513 | - console.log("createContactButton fail", res); | |
514 | - }, | |
515 | - complete(res) { | |
516 | - console.log("createContactButton complete", res); | |
399 | + public static setUserWxCloudStorage(data: object) { | |
400 | + if (cc.sys.platform != cc.sys.WECHAT_GAME || !DataService.I.Authorize) return null; | |
401 | + wx.setUserCloudStorage({ | |
402 | + KVDataList: [{ key: 'data', value: JSON.stringify(data) }], | |
403 | + success: res => { | |
404 | + console.log("分数上传 成功", data); | |
517 | 405 | }, |
406 | + fail: res => { | |
407 | + console.log("分数上传 失败"); | |
408 | + } | |
518 | 409 | }); |
410 | + | |
519 | 411 | } |
412 | + public static showRankEnter() { | |
413 | + return WxHelper.isOperable && AlipayApi.I.canUseRank() | |
414 | + } | |
415 | + public static getRank(key: string) { | |
416 | + if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
417 | + AlipayApi.I.getRankList(key).then(() => { | |
418 | + console.log('success 关闭banner') | |
419 | + // BannerManager.I.hideAll(); | |
420 | + }).catch((msg) => { | |
421 | + console.log('fail', JSON.stringify(msg)) | |
422 | + // WxHelper.showToast(msg.errMsg || msg.errorMessage || '排行榜获取失败') | |
423 | + }); | |
424 | + } | |
520 | 425 | |
521 | - public static restartMiniProgram() { | |
522 | - if (typeof my != 'undefined') { | |
523 | - game.restart(); | |
524 | - return; | |
426 | + } | |
427 | + public static setRankScore(key: string, score: number, updateType?: number) { | |
428 | + if (cc.sys.platform === cc.sys.ALIPAY_GAME) | |
429 | + AlipayApi.I.setRankScoreData(key, score, updateType); | |
430 | + } | |
431 | + public static async loginWx(isAuthorize: boolean, failFunction?: Function, count?: number, success?: Function): Promise<any> { | |
432 | + count = count != undefined ? count : 3; | |
433 | + let data = await SDKTools.login(isAuthorize); | |
434 | + // console.error(count, 'loginWx', data) | |
435 | + if (data.code == 0) { | |
436 | + success && success(); | |
437 | + return data; | |
438 | + } else if (count >= 0) { | |
439 | + count--; | |
440 | + return await this.loginWx(isAuthorize, failFunction, count); | |
441 | + } else if (failFunction) { | |
442 | + console.warn('--wxlogin--fail', data) | |
443 | + failFunction(); | |
444 | + return null; | |
525 | 445 | } |
526 | - if (!this.isWx) { | |
527 | - return | |
528 | - }; | |
529 | - if (!wx.restartMiniProgram) { | |
530 | - this.showToast("自动重启失败,请手动重启!", 10000); | |
446 | + } | |
447 | + | |
448 | + | |
449 | + | |
450 | + | |
451 | + | |
452 | + public static goToGameCenter(success: Function, fail: Function) { | |
453 | + //每个游戏跳转游戏中心的url 不一样 | |
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) { | |
456 | + AlipayApi.I.navigateToMiniProgramByScheme(url, success, fail) | |
531 | 457 | } |
532 | - wx.restartMiniProgram(); | |
533 | 458 | } |
459 | + | |
534 | 460 | } |
535 | 461 | \ No newline at end of file | ... | ... |
sdk/shareTools.ts
1 | -import { UIManager } from "../../framework/core/view/UIManager"; | |
2 | -import { AudioManager } from "../../framework/mananger/AudioManager"; | |
3 | -import TAMgr from "../../framework/ta/TAMgr"; | |
4 | -import WXSDK from "../../framework/wxsdk/WXSDK"; | |
5 | -import { EventModels, EventPool } from "../const/EventModels"; | |
6 | -import { GameConst } from "../const/GameConst"; | |
7 | -import { EActivitySubTaskType, EWindowExitCode, WindowType } from "../const/types"; | |
8 | -import { mapController } from "../modules/map/MapController"; | |
9 | -import { PayShopManager } from "../modules/server/manager/PayShopManager"; | |
10 | -import { shopController } from "../modules/shop/ShopController"; | |
11 | -import { Utils } from "../utils/Utils"; | |
12 | -import MaskView from "../view/common/MaskView"; | |
1 | +import SDKUtils from "../wxsdk/utils/SDKUtils"; | |
2 | +import WXSDK from "../wxsdk/WXSDK"; | |
13 | 3 | import { Analytics } from "./Analytics"; |
14 | -import { Ge } from "./Ge"; | |
15 | -import { SDKTools } from "./SDKTools"; | |
16 | -import { WxHelper } from "./WxHelper"; | |
17 | - | |
4 | +import SDKShare from "../wxsdk/share/SDKShare"; | |
5 | +import { ShareVideoError } from "../wxsdk/base/SDKConst"; | |
18 | 6 | /* |
19 | 7 | * 分享与视频工具类; |
20 | 8 | */ |
... | ... | @@ -25,126 +13,92 @@ export class ShareTools { |
25 | 13 | public static onShowAd: boolean = false; |
26 | 14 | |
27 | 15 | public static isTest: boolean = false; |
28 | - | |
29 | - // private static getAdCount() { | |
30 | - // try { | |
31 | - // let adCount = SDKTools.getParamsString("ad_count", '10,10'); | |
32 | - // let arr = adCount.split(',').map(Number); | |
33 | - // if (SDKTools.isnew) { | |
34 | - // return +arr[0]; | |
35 | - // } else { | |
36 | - // return +arr[1]; | |
37 | - // } | |
38 | - // } catch (error) { | |
39 | - // return 10; | |
40 | - // } | |
41 | - // } | |
42 | 16 | /** |
43 | 17 | * 验证分享:可处理成功、失败 |
44 | 18 | * @param shareKey |
45 | 19 | * @param params params.fail 有就不处理,没有自动处理 |
46 | 20 | * @param opts 目前支持4个key 1,title自定义分享标题 2,img_url自定义分享图片 3,share_type(不走后台配置写死走视频or分享。1分享2视频3无视频则分享)4,closeSimulate是否关闭模拟分享 |
47 | 21 | */ |
48 | - static async share(shareKey: string, params?: { success?: Function, fail?: Function, context?: any }, opts?: any) { | |
49 | - const type = this.getShareType(shareKey); | |
50 | - // 免广告卡、体验卡 | |
51 | - if ((type == 2 && (!opts || opts.share_type != 1)) || (opts && opts.share_type == 2)) { | |
52 | - if (PayShopManager.I.isExperienceOrNoAd()) { | |
53 | - Analytics.I.dot("video_no_ad", { form: shareKey }); | |
54 | - params && params.success && params.success(); | |
55 | - return; | |
56 | - } else { | |
57 | - // 非免广告卡、体验卡用户 检查是否买过体验卡 | |
58 | - if (PayShopManager.I.checkShowExperience()) { | |
59 | - if (shopController.buyExperienceTips != Utils.getDayTime(0)) { | |
60 | - shopController.buyExperienceTips = Utils.getDayTime(0);; | |
61 | - UIManager.instance.showWindow2(WindowType.ExperienceGiftWindow); | |
62 | - params && params.fail && params.fail(); | |
63 | - return; | |
64 | - } | |
65 | - } | |
66 | - } | |
67 | - } | |
68 | - // 广告卡 | |
69 | - if (((type == 2 && (!opts || opts.share_type != 1)) || (opts && opts.share_type == 2)) && mapController.getPackageItemNum(GameConst.ITEM_ADCARD_ID) > 0) { | |
70 | - const ret = await UIManager.instance.waitWindow2(WindowType.AdCardWindow); | |
71 | - if (ret == EWindowExitCode.Yes) { | |
72 | - Analytics.I.dot("ad_card", { ad_card: shareKey }); | |
73 | - params && params.success && params.success(); | |
74 | - return; | |
75 | - } | |
76 | - } | |
77 | - | |
78 | - if ((typeof wx == 'undefined'&&typeof my == 'undefined') || this.isTest) { | |
22 | + static share(shareKey: string, params?: { success?: Function, fail?: Function, context?: any }, opts?: any) { | |
23 | + if (typeof my === 'undefined' || this.isTest) { | |
79 | 24 | params && params.success && params.success(); |
80 | - // 分享 | |
81 | - const evt = EventPool.get(EventModels.AcitvitySubTaskEvent); | |
82 | - evt.type = EActivitySubTaskType.Share; | |
83 | - evt.centerEmit(); | |
84 | 25 | return |
85 | 26 | } |
86 | - | |
87 | - // // 看广告n次后处理为分享 | |
88 | - // let count = this.getAdCount(); | |
89 | - // let isClear = false; | |
90 | - // // console.log("改为分享前:", settingsController.videoCount, count); | |
91 | - // if (settingsController.videoCount >= count) { | |
92 | - // if (type != 1 || (opts && opts.share_type == 2)) {// 视频 or // 强制视频 | |
93 | - // opts = { | |
94 | - // ...opts, | |
95 | - // share_type: 1,//强制改为分享 | |
96 | - // }; | |
97 | - // isClear = true; | |
98 | - // // console.log("改为分享了"); | |
99 | - // } | |
100 | - // } | |
101 | - | |
102 | - this.onShowAd = true; | |
103 | - AudioManager.I.pauseAll(); | |
104 | - if (!opts || !opts.closeSimulate) { | |
105 | - MaskView.Show() | |
27 | + let time = 1500; | |
28 | + let self = this; | |
29 | + if (SDKUtils.compareVersion(my.env.clientVersion, '10.3.70') < 0) { | |
30 | + Analytics.I.dot('videoFail', { "from": 'versionLow' }); | |
31 | + my.showToast({ | |
32 | + type: 'none', | |
33 | + content: '当前版本不支持视频广告哦,请您升级支付宝版本', | |
34 | + duration: time, | |
35 | + }); | |
36 | + return; | |
106 | 37 | } |
38 | + this.onShowAd = true; | |
39 | + | |
107 | 40 | WXSDK.share.share(shareKey.toString(), params, opts).then(async res => { |
108 | 41 | this.onShowAd = false; |
109 | - // if (isClear) { | |
110 | - // settingsController.videoCount = 0; | |
111 | - // } | |
112 | - if (res.type == 2) { | |
113 | - // 视频 | |
114 | - // settingsController.videoCount++; | |
115 | - Ge.I.adShowEvent("video", shareKey.toString()); | |
116 | - TAMgr.Ins.userAdd({ total_ad_num: 1 }); | |
117 | - } else { | |
118 | - // 分享 | |
119 | - const evt = EventPool.get(EventModels.AcitvitySubTaskEvent); | |
120 | - evt.type = EActivitySubTaskType.Share; | |
121 | - evt.centerEmit(); | |
122 | - TAMgr.Ins.dot('share_source', { from: shareKey }); | |
123 | - } | |
124 | 42 | params && params.success && params.success(res); |
125 | - AudioManager.I.resumeAll(); | |
126 | - MaskView.Hide(); | |
127 | - }).catch(async err => { | |
128 | - AudioManager.I.resumeAll(); | |
129 | - MaskView.Hide(); | |
130 | - this.onShowAd = false; | |
131 | - if (!params || !params.fail) { | |
132 | - if (err && err.msg) { | |
133 | - WxHelper.showToast(err.msg) | |
134 | - } | |
43 | + }).catch(async videoErr => { | |
44 | + console.log(JSON.stringify(videoErr)); | |
45 | + let showShare = !(videoErr.code == ShareVideoError.VideoPlaying.code || videoErr.code == ShareVideoError.VideoQuit.code); | |
46 | + if (showShare && SDKUtils.compareVersion(my.env.clientVersion, '10.1.75') > 0) { | |
47 | + SDKShare.I.share(shareKey, params, opts).then(success => { | |
48 | + params && params.success && params.success(success); | |
49 | + Analytics.I.dot('videoFail', { "from": 'share_success' }); | |
50 | + }).catch(shareErr => { | |
51 | + console.log(`share fail${JSON.stringify(shareErr)}`) | |
52 | + Analytics.I.dot('videoFail', { "from": 'share_fail' }); | |
53 | + self.onShowAd = false; | |
54 | + if (!params || !params.fail) { | |
55 | + if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
56 | + wx.showToast({ | |
57 | + title: shareErr.msg, | |
58 | + icon: 'none', | |
59 | + duration: time | |
60 | + }) | |
61 | + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
62 | + Analytics.I.dot('videoFail', { "from": 'other3_' + shareErr.code }); | |
63 | + my.showToast({ | |
64 | + content: shareErr.msg, | |
65 | + type: 'none', | |
66 | + duration: 1500 | |
67 | + }) | |
68 | + } | |
69 | + } else { | |
70 | + Analytics.I.dot('videoFail', { "from": 'other4_' + shareErr.code }); | |
71 | + params && params.fail && params.fail(shareErr); | |
72 | + } | |
73 | + }) | |
135 | 74 | } else { |
136 | - params && params.fail && params.fail(err); | |
75 | + Analytics.I.dot('videoFail', { "from": 'share_versionLow' }); | |
76 | + this.onShowAd = false; | |
77 | + if (!params || !params.fail) { | |
78 | + if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
79 | + wx.showToast({ | |
80 | + title: videoErr.msg, | |
81 | + icon: 'none', | |
82 | + duration: time | |
83 | + }) | |
84 | + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
85 | + Analytics.I.dot('videoFail', { "from": 'other1_' + videoErr.code }); | |
86 | + my.showToast({ | |
87 | + content: videoErr.msg, | |
88 | + type: 'none', | |
89 | + duration: 1500 | |
90 | + }) | |
91 | + } | |
92 | + } else { | |
93 | + Analytics.I.dot('videoFail', { "from": 'other2_' + videoErr.code }); | |
94 | + params && params.fail && params.fail(videoErr); | |
95 | + } | |
137 | 96 | } |
138 | - }) | |
139 | - } | |
140 | 97 | |
141 | - /** | |
142 | - * 必定视频 不走后台配置 | |
143 | - * @param shareKey | |
144 | - * @param params | |
145 | - */ | |
146 | - static video(shareKey: string, params?: { success?: Function, fail?: Function, context?: any }, opts?: any) { | |
147 | - this.share(shareKey, params, { ...opts, share_type: 2 }); | |
98 | + | |
99 | + | |
100 | + | |
101 | + })//this.buildParams(params) | |
148 | 102 | } |
149 | 103 | /** |
150 | 104 | * 纯净分享 不处理回调 |
... | ... | @@ -175,11 +129,9 @@ export class ShareTools { |
175 | 129 | } |
176 | 130 | } |
177 | 131 | |
178 | - /** | |
179 | - * 分享到朋友圈 bate 只支持安卓 | |
180 | - */ | |
181 | - static onShareTimeline(title: string, imageUrl: string, imagePreviewUrl?: string, query?: string) { | |
182 | - WXSDK.share.onShareTimeline(title, imageUrl, imagePreviewUrl, query); | |
183 | - } | |
132 | +} | |
133 | + | |
134 | + | |
184 | 135 | |
136 | +export enum ShareKey { | |
185 | 137 | } | ... | ... |
wxsdk/WXSDK.ts
... | ... | @@ -7,10 +7,9 @@ import LogService from "./service/LogService"; |
7 | 7 | import AdService from "./service/AdService"; |
8 | 8 | import OnlineService from "./service/OnlineService"; |
9 | 9 | import WxInterstitial from "./wx/WxInterstitial"; |
10 | -import { sys } from "cc"; | |
11 | 10 | export default class WXSDK { |
12 | 11 | public static get isWx(): boolean { |
13 | - return typeof wx != "undefined" | |
12 | + return typeof (my) != "undefined" | |
14 | 13 | } |
15 | 14 | public static get data(): SdkData { |
16 | 15 | return DataService.I.Data; |
... | ... | @@ -37,19 +36,38 @@ export default class WXSDK { |
37 | 36 | |
38 | 37 | |
39 | 38 | public static async init() { |
40 | - if (this.isWx) { | |
39 | + // if (this.isWx) { | |
40 | + // WxInit.I.init(); | |
41 | + // //视频预加载 启动预加载视频会闪屏 | |
42 | + // // setTimeout(() => { | |
43 | + // // WxInterstitial.initInterstitialAd();//插屏预加载 | |
44 | + // // ShareVideoService.I.preloadVideo(); | |
45 | + // // }, 2000); | |
46 | + // if (this.isWx) { | |
47 | + // setTimeout(() => { | |
48 | + // WxInterstitial.initInterstitialAd();//插屏预加载 | |
49 | + // ShareVideoService.I.preloadVideo(); | |
50 | + // }, 2000); | |
51 | + // } | |
52 | + // } | |
53 | + // DataService.I.updateTodayOnlineTime(); | |
54 | + // await this.game.env(); | |
55 | + // if (this.isWx) { | |
56 | + // ShareVideoService.I.init(); | |
57 | + // } | |
58 | + // return Promise.resolve(); | |
59 | + if (cc.sys.platform === cc.sys.ALIPAY_GAME || cc.sys.platform === cc.sys.WECHAT_GAME) { | |
41 | 60 | WxInit.I.init(); |
42 | - //视频预加载 启动预加载视频会闪屏 | |
43 | - if (typeof wx !='undefined') { | |
61 | + // 视频预加载 启动预加载视频会闪屏 | |
62 | + // if (cc.sys.platform === cc.sys.WECHAT_GAME && typeof qq == 'undefined') { | |
63 | + if (typeof qq == 'undefined') { | |
44 | 64 | setTimeout(() => { |
45 | - // WxInterstitial.initInterstitialAd();//插屏预加载 | |
65 | + WXSDK.ad.initInterstitialAd();//插屏预加载 | |
46 | 66 | ShareVideoService.I.preloadVideo(); |
47 | 67 | }, 2000); |
48 | 68 | } |
49 | - } | |
50 | - DataService.I.updateTodayOnlineTime(); | |
51 | - await this.game.env(); | |
52 | - if (this.isWx) { | |
69 | + DataService.I.updateTodayOnlineTime(); | |
70 | + await this.game.env(); | |
53 | 71 | ShareVideoService.I.init(); |
54 | 72 | } |
55 | 73 | return Promise.resolve(); | ... | ... |
wxsdk/alipay/AlipayApi.ts
... | ... | @@ -9,6 +9,7 @@ import WxSystem from "../wx/WxSystem"; |
9 | 9 | import { SDKApi } from "../http/SDKApi"; |
10 | 10 | |
11 | 11 | export default class AlipayApi { |
12 | + private _requirementVersion = { rank: '10.5.6' } | |
12 | 13 | private getVersionError(version: string): { errMsg: string; errCode: number } { |
13 | 14 | return { errMsg: `支持最低版本:${version}`, errCode: -1 }; |
14 | 15 | } |
... | ... | @@ -100,7 +101,7 @@ export default class AlipayApi { |
100 | 101 | * 创建激励视频广告组件 |
101 | 102 | */ |
102 | 103 | createRewardedVideoAd(adUnitId: string) { |
103 | - // if (!this.canIUse(Version.I.getVRewardedVideoAd())) return null; | |
104 | + if (!this.canIUse(Version.I.getVRewardedVideoAd())) return null; | |
104 | 105 | return my.createRewardedAd({ |
105 | 106 | adUnitId: adUnitId, |
106 | 107 | }); |
... | ... | @@ -229,14 +230,15 @@ export default class AlipayApi { |
229 | 230 | my.onShareAppMessage = function () { |
230 | 231 | return { |
231 | 232 | title: data.title, |
232 | - bgImgUrl:'https://wxsdk-cdn.miso-lab.com/moon-island/share/zfbshare.jpeg', | |
233 | 233 | // desc: , |
234 | - scImgUrl: data.imageUrl, | |
234 | + imageUrl: data.imageUrl, | |
235 | 235 | success: function (res) { |
236 | - console.log(res); | |
236 | + // console.log(res); | |
237 | + // callback.success() | |
237 | 238 | }, |
238 | 239 | fail: function (e) { |
239 | - console.log(e); | |
240 | + // console.log(e); | |
241 | + // callback.fail() | |
240 | 242 | }, |
241 | 243 | complete: function (e) { |
242 | 244 | |
... | ... | @@ -246,10 +248,12 @@ export default class AlipayApi { |
246 | 248 | |
247 | 249 | return my.showSharePanel({ |
248 | 250 | success: () => { |
251 | + // console.log('showSharePanel aa') | |
249 | 252 | callback.success(); |
250 | 253 | |
251 | 254 | }, |
252 | 255 | fail: () => { |
256 | + // console.log('showSharePanel fail') | |
253 | 257 | callback.fail(); |
254 | 258 | }, |
255 | 259 | complete: (e) => { |
... | ... | @@ -291,13 +295,30 @@ export default class AlipayApi { |
291 | 295 | }); |
292 | 296 | } |
293 | 297 | |
298 | + | |
299 | + /** | |
300 | + * 如果是从别的小程序内跳转过来的,关闭的时候需要回到之前的小程序 | |
301 | + */ | |
302 | + navigateBackMiniProgram() { | |
303 | + my.navigateBackMiniProgram({ | |
304 | + extraData: { | |
305 | + | |
306 | + }, | |
307 | + success: (res) => { | |
308 | + console.log(res) | |
309 | + }, | |
310 | + fail: (err) => { | |
311 | + console.log(err) | |
312 | + } | |
313 | + }); | |
314 | + } | |
315 | + | |
294 | 316 | navigateToMiniProgram(appId: string, path: string, opts: any = {}) { |
295 | 317 | return new Promise((resolve, reject) => { |
296 | - wx.navigateToMiniProgram({ | |
318 | + my.navigateToMiniProgram({ | |
297 | 319 | appId, |
298 | 320 | path, |
299 | 321 | extraData: opts.extraData || {}, |
300 | - envVersion: opts.envVersion || 'release', | |
301 | 322 | success(res: any) { |
302 | 323 | resolve(res); |
303 | 324 | }, |
... | ... | @@ -307,6 +328,64 @@ export default class AlipayApi { |
307 | 328 | }); |
308 | 329 | }); |
309 | 330 | } |
331 | + // 将 scheme 转换为 my.navigateToMiniProgram 的参数 scheme为外部app打开地址 游戏内需要转 | |
332 | + private schemeToParams(scheme) { | |
333 | + if (!scheme.startsWith('alipays:')) { | |
334 | + return { message: '! 非 alipays: 开头' }; | |
335 | + } | |
336 | + var params = {}; | |
337 | + var parseQuery = (str) => { | |
338 | + return str.replace(/^.*?\?/, '').split('&').map(s => { | |
339 | + var p = s.includes('=') ? s.indexOf('=') : s.length; | |
340 | + return [s.slice(0, p), s.slice(p + 1)].map(decodeURIComponent); | |
341 | + }); | |
342 | + }; | |
343 | + for (var [k, v] of parseQuery(scheme)) { | |
344 | + if (k == 'appId') { | |
345 | + if (v.length != 16) { | |
346 | + return { message: `! 非 16 位 appId '${v}'` }; | |
347 | + } | |
348 | + } else if (k == 'chInfo') { | |
349 | + let tempkey = 'startParam'; | |
350 | + let tempValue = params[tempkey] || {}; | |
351 | + tempValue[k] = v; | |
352 | + params[tempkey] = tempValue; | |
353 | + continue; | |
354 | + } else { | |
355 | + continue; | |
356 | + } | |
357 | + // else if (k == 'page') { | |
358 | + // k = 'path'; | |
359 | + // } else if (k == 'query') { | |
360 | + // var o = {}; | |
361 | + // for (var [x, y] of parseQuery(v)) { | |
362 | + // o[x] = y; | |
363 | + // } | |
364 | + // v = o; | |
365 | + // } else if (k == '') { | |
366 | + // continue; | |
367 | + // } else { | |
368 | + // let extraData = 'extraData'; | |
369 | + // let newV = params[extraData] || {}; | |
370 | + // newV[k] = v; | |
371 | + // v = newV; | |
372 | + // k = extraData; | |
373 | + // } | |
374 | + params[k] = v; | |
375 | + } | |
376 | + return { params }; | |
377 | + } | |
378 | + navigateToMiniProgramByScheme(scheme, success, fail) { | |
379 | + let { params, message } = this.schemeToParams(scheme); | |
380 | + console.log('params--', { ...params }); | |
381 | + if (cc.sys.platform != cc.sys.ALIPAY_GAME) return | |
382 | + if (params) { | |
383 | + my.navigateToMiniProgram({ ...params, success, fail,}); | |
384 | + } else { | |
385 | + fail && fail({ error: -1, errorMessage: `无效的小程序 scheme ${scheme}: ${message}` }); | |
386 | + } | |
387 | + } | |
388 | + | |
310 | 389 | |
311 | 390 | /** |
312 | 391 | * login获取code接口 |
... | ... | @@ -388,15 +467,15 @@ export default class AlipayApi { |
388 | 467 | */ |
389 | 468 | requestMidasPayment(params: { mode: string; env: number; offerId: string; currencyType: string; platform: string; buyQuantity: number; zoneId: string }): Promise<any> { |
390 | 469 | let { mode, env, offerId, currencyType, platform, buyQuantity, zoneId } = params; |
391 | - console.warn('====> PCSDK AlipayApi requestMidasPayment 支付参数', { | |
392 | - mode, | |
393 | - env, | |
394 | - offerId, | |
395 | - currencyType, | |
396 | - platform, | |
397 | - buyQuantity, | |
398 | - zoneId | |
399 | - }); | |
470 | + // console.warn('====> PCSDK AlipayApi requestMidasPayment 支付参数', { | |
471 | + // mode, | |
472 | + // env, | |
473 | + // offerId, | |
474 | + // currencyType, | |
475 | + // platform, | |
476 | + // buyQuantity, | |
477 | + // zoneId | |
478 | + // }); | |
400 | 479 | return new Promise((resolve, reject) => { |
401 | 480 | wx.requestMidasPayment({ |
402 | 481 | mode, |
... | ... | @@ -459,19 +538,117 @@ export default class AlipayApi { |
459 | 538 | action_code, |
460 | 539 | action_finish_channel |
461 | 540 | }; |
462 | - return SDKApi.incrementGameaction(params).then(() => { | |
463 | - // my.confirm({ | |
464 | - // title: '增加量行为', | |
465 | - // content: `${action_code}`, | |
466 | - // confirmButtonText: ``, | |
467 | - // cancelButtonText: '暂不需要', | |
468 | - // success: (result) => { | |
469 | - // }, | |
470 | - // }); | |
541 | + return SDKApi.aliMission(params).then(() => { | |
471 | 542 | resolve(null) |
472 | 543 | }) |
473 | 544 | }) |
474 | 545 | } |
546 | + //段位 | |
547 | + setRankSegmentData(rankKey: string, segment: number, segmentName: string) { | |
548 | + return new Promise((resolve, reject) => { | |
549 | + if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) | |
550 | + if (!this.canIUse('10.5.6')) return reject(this.getVersionError('10.5.6')); | |
551 | + my.setImRankData({ | |
552 | + rankId: rankKey, | |
553 | + dataType: 1, //1 为枚举类型。用于传段位信息。 | |
554 | + value: segmentName, //该用户得了999999分,dataType为0时,需填入正数的字符串 | |
555 | + priority: segment, //段位权重 | |
556 | + updateType: 0, // 0为覆盖更新,1为破纪录更新。 | |
557 | + success(res) { | |
558 | + console.log(res); | |
559 | + resolve(res); | |
560 | + }, | |
561 | + fail(res) { | |
562 | + console.log('fail->', res); | |
563 | + reject(res) | |
564 | + }, | |
565 | + // complete(res) { | |
566 | + // console.log(res); | |
567 | + // } | |
568 | + }); | |
569 | + }); | |
570 | + } | |
571 | + //排行榜成绩 | |
572 | + setRankScoreData(rankKey: string, score: number, updateType: number = 1) { | |
573 | + | |
574 | + return new Promise((resolve, reject) => { | |
575 | + if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) | |
576 | + if (!this.canIUse(this._requirementVersion.rank)) return reject(this.getVersionError(this._requirementVersion.rank)); | |
577 | + my.setImRankData({ | |
578 | + rankId: rankKey, | |
579 | + dataType: 0, //成绩为数字类型 | |
580 | + value: score.toString(), //该用户得了999999分,dataType为0时,需填入正数的字符串 | |
581 | + priority: 0, //dataType为0时,可不传。 | |
582 | + updateType: updateType, // 0为覆盖更新,1为破纪录更新。 | |
583 | + success(res) { | |
584 | + console.log('add-> success', res); | |
585 | + resolve(res); | |
586 | + }, | |
587 | + fail(res) { | |
588 | + console.log('add fail->', res); | |
589 | + reject(res) | |
590 | + } | |
591 | + // complete(res) { | |
592 | + // console.log(res); | |
593 | + // } | |
594 | + }); | |
595 | + }); | |
596 | + } | |
597 | + | |
598 | + canUseRank() { | |
599 | + return this.canIUse(this._requirementVersion.rank) | |
600 | + } | |
601 | + /** | |
602 | + * | |
603 | + * @param rankKey 排行榜唯一ID,唯一标识游戏内的排行榜。 | |
604 | + * @param scorePrefix 排行榜成绩值前缀。 | |
605 | + * @param scoreSuffix 排行榜成绩值后缀。 | |
606 | + */ | |
607 | + getRankList(rankKey: string, scorePrefix?: string, scoreSuffix?: string) { | |
608 | + return new Promise((resolve, reject) => { | |
609 | + if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) | |
610 | + if (!this.canIUse(this._requirementVersion.rank)) return reject(this.getVersionError(this._requirementVersion.rank)); | |
611 | + my.getImRankList({ | |
612 | + rankId: rankKey, | |
613 | + // headImg: '', // 排行榜头部 | |
614 | + scorePrefix: scorePrefix, // 成绩值前缀 | |
615 | + scoreSuffix: scoreSuffix, // 成绩值后缀 | |
616 | + success(res) { | |
617 | + // console.log(res); | |
618 | + resolve(res); | |
619 | + }, | |
620 | + fail(res) { | |
621 | + console.log('getImRankList fail->', JSON.stringify(res)); | |
622 | + reject(res) | |
623 | + }, | |
624 | + // complete(res) { | |
625 | + // console.log(res); | |
626 | + // } | |
627 | + }); | |
628 | + }) | |
629 | + } | |
630 | + | |
631 | + //玩一玩小程序是否已加首咨询 | |
632 | + isAddHomePage(): Promise<boolean> { | |
633 | + return new Promise((resolve, reject) => { | |
634 | + if (window['my'] == undefined) return reject(false); | |
635 | + let uid = DataService.I.UserId; | |
636 | + let token = DataService.I.Token; | |
637 | + let openid = DataService.I.OpenId; | |
638 | + let params = { | |
639 | + uid, | |
640 | + token, | |
641 | + openid, | |
642 | + }; | |
643 | + SDKApi.isAddHomePage(params).then((data) => { | |
644 | + console.log('--->设首结果', data) | |
645 | + //Y:已添加首页,N:未添加首页 | |
646 | + return resolve(data?.data.consult_result == 'Y') | |
647 | + }).catch(() => { | |
648 | + return reject(false); | |
649 | + }) | |
650 | + }) | |
651 | + } | |
475 | 652 | |
476 | 653 | |
477 | 654 | private static _instance: AlipayApi; | ... | ... |
wxsdk/alipay/AlipayBanner.ts
1 | 1 | |
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 | -// import WxSystem from "../wx/WxSystem"; | |
7 | -// import AlipayApi from "./AlipayApi"; | |
8 | - | |
9 | - | |
10 | -// /* | |
11 | -// * banner | |
12 | -// */ | |
13 | -// export default class AlipayBanner { | |
14 | -// private static instance: AlipayBanner; | |
15 | -// static get I(): AlipayBanner { | |
16 | -// return this.instance || (this.instance = new AlipayBanner(750, 750)); | |
17 | -// } | |
18 | -// private designWidth: number; | |
19 | -// private bannerWidth: number; | |
20 | -// private bannerHeight: number; | |
21 | -// private bannerScale: number; | |
22 | -// private bannerParams: any; | |
23 | -// private _isErrored: boolean; | |
24 | -// private adUnitId: string; | |
25 | -// private bannerAd: any; | |
26 | -// private resolve: any; | |
27 | -// private reject: any; | |
28 | - | |
29 | -// constructor(designWidth: number, bannerWidth: number) { | |
30 | -// designWidth = designWidth || 750; | |
31 | -// bannerWidth = bannerWidth || 750; | |
32 | - | |
33 | -// this.adUnitId = ''; | |
34 | -// this._isErrored = false; | |
35 | -// this.designWidth = designWidth; | |
36 | -// this.bannerScale = WxSystem.I.winWidth / this.designWidth; | |
37 | -// this.bannerWidth = Math.max(this.bannerScale * bannerWidth, 300); | |
38 | -// this.bannerHeight = WxSystem.I.winHeight / this.bannerScale; | |
39 | -// } | |
40 | - | |
41 | -// get isErrored() { | |
42 | -// return this._isErrored; | |
43 | -// } | |
44 | - | |
45 | -// private queue: Function[] = []; | |
46 | -// private isEnd: boolean = false; | |
47 | - | |
48 | -// create(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { | |
49 | -// // console.log('wxbanner can not') | |
50 | -// if (SDKUtils.compareVersion(my.env.clientVersion, '10.3.66') < 0) return null; | |
51 | -// // if (!WxApi.I.canIUse(Version.I.getVBannerAd())) | |
52 | -// // console.log('wxbanner can', adUnitId) | |
53 | - | |
54 | -// this.bannerParams = opts || {}; | |
55 | -// if (opts && opts.bannerWidth) { | |
56 | -// this.bannerWidth = opts.bannerWidth; | |
57 | -// } | |
58 | -// this.isEnd = true; | |
59 | -// this.bannerParams.type = this.bannerParams.type || 1; | |
60 | -// this.bannerParams.offsetY = -this.bannerParams.offsetY || 0; | |
61 | -// this.bannerParams.adIntervals = this.bannerParams.adIntervals || 120; | |
62 | -// return new Promise((resolve, reject) => { | |
63 | -// this.resolve = resolve; | |
64 | -// this.reject = reject; | |
65 | -// this._isErrored = false; | |
66 | -// this.adUnitId = adUnitId; | |
67 | - | |
68 | -// if (SDKUtils.isEmpty(adUnitId)) { | |
69 | -// AlipayBanner.I.handleQueue(); | |
70 | -// return this.reject({ ...BannerError.BannerInvalid, adUnitId: this.adUnitId }); | |
71 | -// } | |
72 | - | |
73 | -// // 设置样式(hack:修复qq版本) | |
74 | -// this.bannerParams.type === 2 && (this.bannerWidth = WxSystem.I.winWidth); | |
75 | -// let style = { top: 0, left: (WxSystem.I.winWidth - this.bannerWidth) / 2, width: this.bannerWidth }; | |
76 | -// style = { | |
77 | -// ...style, | |
78 | -// top: WxSystem.I.winHeight - 100, | |
79 | -// }; | |
80 | -// // 创建并判断是否存在 | |
81 | -// // if (this.bannerParams.type === 2) | |
82 | -// // this.bannerAd = wx.createGameBanner({ adUnitId, style: { left: style.left, top: this.bannerHeight } }); | |
83 | -// // else | |
84 | -// if (this.bannerAd) { | |
85 | -// if (!opts || (opts && !opts.isOff)) { | |
86 | -// this.show(false); | |
87 | -// } | |
88 | -// return | |
89 | -// } | |
90 | -// this.bannerAd = AlipayApi.I.createBannerAd(adUnitId, style); | |
91 | -// LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.request) | |
92 | -// if (!this.bannerAd) { | |
93 | -// AlipayBanner.I.handleQueue(); | |
94 | -// return this.reject({ ...BannerError.BannerNotOpen, adUnitId: this.adUnitId }); | |
95 | -// } | |
96 | -// this.bannerAd.onLoad(this.onLoad); | |
97 | -// this.bannerAd.onError(this.onError); | |
98 | -// //支付宝无这个方法!!! | |
99 | -// // this.bannerAd.onResize(this.onResize); | |
100 | -// if (!opts || (opts && !opts.isOff)) { | |
101 | -// this.show(false); | |
102 | -// } | |
103 | -// }); | |
104 | -// } | |
105 | - | |
106 | -// /** | |
107 | -// * | |
108 | -// * @param bol | |
109 | -// */ | |
110 | -// show(bol: boolean = true): boolean { | |
111 | -// if (AlipayBanner.I.isEnd && bol) { | |
112 | -// AlipayBanner.I.queue.push(AlipayBanner.I.show.bind(AlipayBanner.I)) | |
113 | -// return | |
114 | -// } | |
115 | -// AlipayBanner.I.isEnd = true | |
116 | -// if (this.bannerAd) { | |
117 | -// if (this.bannerAd.style.realHeight) | |
118 | -// this.bannerAd.style.top = WxSystem.I.winHeight - this.bannerAd.style.realHeight + this.bannerParams.offsetY; | |
119 | -// if (this.bannerParams.type === 2) { | |
120 | -// if (this.bannerAd.style.width) | |
121 | -// this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerAd.style.width) / 2; | |
122 | -// else | |
123 | -// this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerWidth) / 2; | |
124 | -// } else | |
125 | -// this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerWidth) / 2; | |
126 | - | |
127 | -// LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.show) | |
128 | -// this.bannerAd.show().catch((err: any) => this.handleShowError(err)); | |
129 | -// __LOG__ && console.error('wxBanner - show: ' + this.adUnitId, this.bannerAd.style); | |
130 | -// AlipayBanner.I.handleQueue() | |
131 | -// return true; | |
132 | -// } | |
133 | -// AlipayBanner.I.handleQueue() | |
134 | -// return false; | |
135 | -// } | |
136 | - | |
137 | -// hide() { | |
138 | -// let that = AlipayBanner.I; | |
139 | -// if (that.isEnd) { | |
140 | -// that.queue.push(that.hide.bind(that)) | |
141 | -// return | |
142 | -// } | |
143 | -// that.isEnd = true | |
144 | -// if (this.bannerAd) { | |
145 | -// this.bannerAd.style.left = -9999; | |
146 | -// this.bannerAd.hide(); | |
147 | -// LogService.I.adStat('banner', that.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.interrupt) | |
148 | -// __LOG__ && console.error('wxBanner - hide: ' + this.adUnitId); | |
149 | -// } | |
150 | -// that.handleQueue() | |
151 | -// } | |
152 | - | |
153 | -// toggle(isshow: boolean) { | |
154 | -// isshow ? this.show() : this.hide(); | |
155 | -// } | |
156 | - | |
157 | -// destory() { | |
158 | -// if (this.bannerAd) { | |
159 | -// this.bannerAd.style.left = -9999; | |
160 | -// this.bannerAd.destroy(); | |
161 | -// this.bannerAd = null; | |
162 | -// LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.interrupt) | |
163 | -// __LOG__ && console.error('wxBanner - destory: ' + this.adUnitId); | |
164 | -// } | |
165 | -// } | |
166 | - | |
167 | -// private onLoad() { | |
168 | -// let that = AlipayBanner.I; | |
169 | -// let bannerAd = that.bannerAd; | |
170 | -// if (!bannerAd) return; | |
171 | -// // Platform.IsQQ && that.show(); | |
172 | -// __LOG__ && console.error('wxBanner - onLoad: ' + that.adUnitId); | |
173 | -// if (bannerAd.style.realHeight) | |
174 | -// bannerAd.style.top = WxSystem.I.winHeight - bannerAd.style.realHeight + that.bannerParams.offsetY; | |
175 | -// that.unbind(); | |
176 | -// that.handleQueue(); | |
177 | -// that.resolve && that.resolve({ | |
178 | -// adUnitId: that.adUnitId, | |
179 | -// scale: that.bannerScale, | |
180 | -// width: bannerAd.style.realWidth / that.bannerScale, | |
181 | -// height: bannerAd.style.realHeight / that.bannerScale | |
182 | -// }); | |
183 | -// } | |
184 | - | |
185 | -// private onError(err: any, ...params) { | |
186 | -// __LOG__ && console.error('wxBanner - onError', err, JSON.stringify(err), params); | |
187 | -// let that = AlipayBanner.I; | |
188 | -// !that._isErrored && that.handleError(err, { ...BannerError.BannerFail, adUnitId: that.adUnitId }); | |
189 | -// } | |
190 | - | |
191 | -// private onResize() { | |
192 | -// let that = AlipayBanner.I; | |
193 | -// let bannerAd = that.bannerAd; | |
194 | -// if (!bannerAd) return; | |
195 | -// bannerAd.style.top = WxSystem.I.winHeight - bannerAd.style.realHeight + that.bannerParams.offsetY; | |
196 | -// bannerAd.style.left = (WxSystem.I.winWidth - bannerAd.style.realWidth) / 2; | |
197 | -// } | |
198 | - | |
199 | -// private handleShowError(ret: { errCode: number; errMsg: string }) { | |
200 | -// __LOG__ && console.error('wxBanner - handleShowError', ret); | |
201 | -// let that = AlipayBanner.I; | |
202 | -// let { errCode, errMsg } = ret; | |
203 | -// !that.isErrored && that.handleError(ret, { code: errCode, msg: errMsg }); | |
204 | -// } | |
205 | - | |
206 | -// private handleError(ret: any, err: any) { | |
207 | -// let that = AlipayBanner.I; | |
208 | -// that.unbind(); | |
209 | -// that._isErrored = true; | |
210 | -// that.bannerAd = null; | |
211 | -// that.handleQueue() | |
212 | -// LogService.I.adStat('banner', that.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.fail) | |
213 | -// that.reject && that.reject({ ...err, adUnitId: that.adUnitId }); | |
214 | -// __LOG__ && console.error('wxBanner - onError: ' + that.adUnitId, ret, err); | |
215 | -// } | |
216 | - | |
217 | -// private unbind() { | |
218 | -// if (this.bannerAd) { | |
219 | -// // this.bannerAd.offLoad(this.onLoad); | |
220 | -// // this.bannerAd.offError(this.onError); | |
221 | -// // this.bannerAd.offResize(this.onResize); | |
222 | -// } | |
223 | -// } | |
224 | - | |
225 | -// /** | |
226 | -// * 处队列 | |
227 | -// */ | |
228 | -// handleQueue() { | |
229 | -// let that = AlipayBanner.I; | |
230 | -// if (that.queue.length > 0) { | |
231 | -// that.isEnd = false; | |
232 | -// let fn = that.queue.shift(); | |
233 | -// fn(); | |
234 | -// } else { | |
235 | -// that.isEnd = false; | |
236 | -// } | |
237 | -// } | |
238 | -// } | |
239 | 2 | \ No newline at end of file |
3 | +import SDKUtils from "../utils/SDKUtils"; | |
4 | +import { BannerError, __LOG__ } from "../base/SDKConst"; | |
5 | +import LogService from "../service/LogService"; | |
6 | +import { DOT_AD_STATUS, DOT_AD_TYPE } from "../base/SDKEnum"; | |
7 | +import WxSystem from "../wx/WxSystem"; | |
8 | +import AlipayApi from "./AlipayApi"; | |
9 | + | |
10 | + | |
11 | +/* | |
12 | +* banner | |
13 | +*/ | |
14 | +export default class AlipayBanner { | |
15 | + private static instance: AlipayBanner; | |
16 | + static get I(): AlipayBanner { | |
17 | + return this.instance || (this.instance = new AlipayBanner(750, 750)); | |
18 | + } | |
19 | + private designWidth: number; | |
20 | + private bannerWidth: number; | |
21 | + private bannerHeight: number; | |
22 | + private bannerScale: number; | |
23 | + private bannerParams: any; | |
24 | + private _isErrored: boolean; | |
25 | + private adUnitId: string; | |
26 | + private bannerAd: any; | |
27 | + private resolve: any; | |
28 | + private reject: any; | |
29 | + private _currentVisible: boolean = false; | |
30 | + constructor(designWidth: number, bannerWidth: number) { | |
31 | + designWidth = designWidth || 750; | |
32 | + bannerWidth = bannerWidth || 750; | |
33 | + | |
34 | + this.adUnitId = ''; | |
35 | + this._isErrored = false; | |
36 | + this.designWidth = designWidth; | |
37 | + this.bannerScale = WxSystem.I.winWidth / this.designWidth; | |
38 | + this.bannerWidth = Math.max(this.bannerScale * bannerWidth, 300); | |
39 | + this.bannerHeight = WxSystem.I.winHeight / this.bannerScale; | |
40 | + } | |
41 | + | |
42 | + get isErrored() { | |
43 | + return this._isErrored; | |
44 | + } | |
45 | + | |
46 | + private queue: Function[] = []; | |
47 | + private isEnd: boolean = false; | |
48 | + | |
49 | + create(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { | |
50 | + // console.log('wxbanner can not') | |
51 | + if (SDKUtils.compareVersion(my.env.clientVersion, '10.3.66') < 0) return null; | |
52 | + // if (!WxApi.I.canIUse(Version.I.getVBannerAd())) | |
53 | + // console.log('wxbanner can', adUnitId) | |
54 | + | |
55 | + this.bannerParams = opts || {}; | |
56 | + if (opts && opts.bannerWidth) { | |
57 | + this.bannerWidth = opts.bannerWidth; | |
58 | + } | |
59 | + this.isEnd = true; | |
60 | + this.bannerParams.type = this.bannerParams.type || 1; | |
61 | + this.bannerParams.offsetY = -this.bannerParams.offsetY || 0; | |
62 | + this.bannerParams.adIntervals = this.bannerParams.adIntervals || 120; | |
63 | + return new Promise((resolve, reject) => { | |
64 | + this.resolve = resolve; | |
65 | + this.reject = reject; | |
66 | + this._isErrored = false; | |
67 | + this.adUnitId = adUnitId; | |
68 | + | |
69 | + if (SDKUtils.isEmpty(adUnitId)) { | |
70 | + AlipayBanner.I.handleQueue(); | |
71 | + return this.reject({ ...BannerError.BannerInvalid, adUnitId: this.adUnitId }); | |
72 | + } | |
73 | + | |
74 | + // 设置样式(hack:修复qq版本) | |
75 | + this.bannerParams.type === 2 && (this.bannerWidth = WxSystem.I.winWidth); | |
76 | + let style = { top: 0, left: (WxSystem.I.winWidth - this.bannerWidth) / 2, width: this.bannerWidth }; | |
77 | + style = { | |
78 | + ...style, | |
79 | + top: WxSystem.I.winHeight - 100, | |
80 | + }; | |
81 | + // 创建并判断是否存在 | |
82 | + // if (this.bannerParams.type === 2) | |
83 | + // this.bannerAd = wx.createGameBanner({ adUnitId, style: { left: style.left, top: this.bannerHeight } }); | |
84 | + // else | |
85 | + if (this.bannerAd) { | |
86 | + if (!opts || (opts && !opts.isOff)) { | |
87 | + this.show(false); | |
88 | + } | |
89 | + return | |
90 | + } | |
91 | + this.bannerAd = AlipayApi.I.createBannerAd(adUnitId, style); | |
92 | + console.log('create new BannerAd') | |
93 | + LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.request) | |
94 | + if (!this.bannerAd) { | |
95 | + AlipayBanner.I.handleQueue(); | |
96 | + return this.reject({ ...BannerError.BannerNotOpen, adUnitId: this.adUnitId }); | |
97 | + } | |
98 | + this.bannerAd.onLoad(this.onLoad); | |
99 | + this.bannerAd.onError(this.onError); | |
100 | + //支付宝无这个方法!!! | |
101 | + // this.bannerAd.onResize(this.onResize); | |
102 | + if (!opts || (opts && !opts.isOff)) { | |
103 | + this.show(false); | |
104 | + } | |
105 | + }); | |
106 | + } | |
107 | + | |
108 | + /** | |
109 | + * | |
110 | + * @param bol | |
111 | + */ | |
112 | + show(bol: boolean = true): boolean { | |
113 | + if (AlipayBanner.I.isEnd && bol) { | |
114 | + AlipayBanner.I.queue.push(AlipayBanner.I.show.bind(AlipayBanner.I)) | |
115 | + return | |
116 | + } | |
117 | + AlipayBanner.I.isEnd = true | |
118 | + if (this.bannerAd && !this._currentVisible) { | |
119 | + if (this.bannerAd.style.realHeight) | |
120 | + this.bannerAd.style.top = WxSystem.I.winHeight - this.bannerAd.style.realHeight + this.bannerParams.offsetY; | |
121 | + if (this.bannerParams.type === 2) { | |
122 | + if (this.bannerAd.style.width) | |
123 | + this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerAd.style.width) / 2; | |
124 | + else | |
125 | + this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerWidth) / 2; | |
126 | + } else | |
127 | + this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerWidth) / 2; | |
128 | + | |
129 | + LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.show) | |
130 | + this._currentVisible = true; | |
131 | + this.bannerAd.show().catch((err: any) => this.handleShowError(err)); | |
132 | + __LOG__ && console.error('wxBanner - show: ' + this.adUnitId, this.bannerAd.style); | |
133 | + AlipayBanner.I.handleQueue() | |
134 | + return true; | |
135 | + } | |
136 | + AlipayBanner.I.handleQueue() | |
137 | + return false; | |
138 | + } | |
139 | + | |
140 | + hide() { | |
141 | + | |
142 | + let that = AlipayBanner.I; | |
143 | + if (that.isEnd) { | |
144 | + that.queue.push(that.hide.bind(that)) | |
145 | + return | |
146 | + } | |
147 | + that.isEnd = true | |
148 | + if (this.bannerAd) { | |
149 | + this.bannerAd.style.left = -9999; | |
150 | + this.bannerAd.hide(); | |
151 | + this._currentVisible = false; | |
152 | + LogService.I.adStat('banner', that.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.interrupt) | |
153 | + __LOG__ && console.error('wxBanner - hide: ' + this.adUnitId); | |
154 | + } | |
155 | + that.handleQueue() | |
156 | + } | |
157 | + | |
158 | + toggle(isshow: boolean) { | |
159 | + isshow ? this.show() : this.hide(); | |
160 | + } | |
161 | + | |
162 | + destory() { | |
163 | + if (this.bannerAd) { | |
164 | + this.bannerAd.style.left = -9999; | |
165 | + this.bannerAd?.destroy(); | |
166 | + this.bannerAd = null; | |
167 | + LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.interrupt) | |
168 | + __LOG__ && console.error('wxBanner - destory: ' + this.adUnitId); | |
169 | + } | |
170 | + } | |
171 | + | |
172 | + private onLoad() { | |
173 | + let that = AlipayBanner.I; | |
174 | + let bannerAd = that.bannerAd; | |
175 | + if (!bannerAd) return; | |
176 | + // Platform.IsQQ && that.show(); | |
177 | + __LOG__ && console.error('wxBanner - onLoad: ' + that.adUnitId); | |
178 | + if (bannerAd.style.realHeight) | |
179 | + bannerAd.style.top = WxSystem.I.winHeight - bannerAd.style.realHeight + that.bannerParams.offsetY; | |
180 | + that.unbind(); | |
181 | + that.handleQueue(); | |
182 | + that.resolve && that.resolve({ | |
183 | + adUnitId: that.adUnitId, | |
184 | + scale: that.bannerScale, | |
185 | + width: bannerAd.style.realWidth / that.bannerScale, | |
186 | + height: bannerAd.style.realHeight / that.bannerScale | |
187 | + }); | |
188 | + } | |
189 | + | |
190 | + private onError(err: any, ...params) { | |
191 | + __LOG__ && console.error('wxBanner - onError', err, JSON.stringify(err), params); | |
192 | + let that = AlipayBanner.I; | |
193 | + !that._isErrored && that.handleError(err, { ...BannerError.BannerFail, adUnitId: that.adUnitId }); | |
194 | + } | |
195 | + | |
196 | + private onResize() { | |
197 | + let that = AlipayBanner.I; | |
198 | + let bannerAd = that.bannerAd; | |
199 | + if (!bannerAd) return; | |
200 | + bannerAd.style.top = WxSystem.I.winHeight - bannerAd.style.realHeight + that.bannerParams.offsetY; | |
201 | + bannerAd.style.left = (WxSystem.I.winWidth - bannerAd.style.realWidth) / 2; | |
202 | + } | |
203 | + | |
204 | + private handleShowError(ret: { errCode: number; errMsg: string }) { | |
205 | + this._currentVisible = false; | |
206 | + __LOG__ && console.error('wxBanner - handleShowError', ret); | |
207 | + let that = AlipayBanner.I; | |
208 | + let { errCode, errMsg } = ret; | |
209 | + !that.isErrored && that.handleError(ret, { code: errCode, msg: errMsg }); | |
210 | + } | |
211 | + | |
212 | + private handleError(ret: any, err: any) { | |
213 | + let that = AlipayBanner.I; | |
214 | + that.unbind(); | |
215 | + that._isErrored = true; | |
216 | + that.bannerAd?.destroy(); | |
217 | + that.bannerAd = null; | |
218 | + that.handleQueue() | |
219 | + LogService.I.adStat('banner', that.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.fail) | |
220 | + that.reject && that.reject({ ...err, adUnitId: that.adUnitId }); | |
221 | + __LOG__ && console.error('wxBanner - onError: ' + that.adUnitId, ret, err); | |
222 | + } | |
223 | + | |
224 | + private unbind() { | |
225 | + if (this.bannerAd) { | |
226 | + // this.bannerAd.offLoad(this.onLoad); | |
227 | + // this.bannerAd.offError(this.onError); | |
228 | + // this.bannerAd.offResize(this.onResize); | |
229 | + } | |
230 | + } | |
231 | + | |
232 | + /** | |
233 | + * 处队列 | |
234 | + */ | |
235 | + handleQueue() { | |
236 | + let that = AlipayBanner.I; | |
237 | + if (that.queue.length > 0) { | |
238 | + that.isEnd = false; | |
239 | + let fn = that.queue.shift(); | |
240 | + fn(); | |
241 | + } else { | |
242 | + that.isEnd = false; | |
243 | + } | |
244 | + } | |
245 | +} | |
240 | 246 | \ No newline at end of file | ... | ... |
wxsdk/alipay/AlipayInterstitial.ts
1 | -// import { GAMEDATA } from "../base/SDKConst"; | |
2 | -// import { DOT_AD_STATUS, DOT_AD_TYPE } from "../base/SDKEnum"; | |
3 | -// import LogService from "../service/LogService"; | |
4 | -// import AlipayApi from "./AlipayApi"; | |
1 | +import { GAMEDATA } from "../base/SDKConst"; | |
2 | +import { DOT_AD_STATUS, DOT_AD_TYPE } from "../base/SDKEnum"; | |
3 | +import LogService from "../service/LogService"; | |
4 | +import AlipayApi from "./AlipayApi"; | |
5 | 5 | |
6 | -// export default class AlipayInterstitial { | |
7 | -// /** 插屏广告ID */ | |
8 | -// private static interstitialAdId: string = GAMEDATA.interstitialAdId; | |
9 | -// /** 插屏广告实例 */ | |
10 | -// public static interstitialAd: any; | |
11 | -// /** 插屏广告是否加载完成 */ | |
12 | -// private static interstitialSuccell: boolean = false; | |
13 | -// /** 初始化插屏广告 */ | |
14 | -// public static initInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { | |
15 | -// this.interstitialAdId = adUnitId; | |
16 | -// this.createInterstitial(); | |
17 | -// } | |
6 | +export default class AlipayInterstitial { | |
7 | + /** 插屏广告ID */ | |
8 | + private static interstitialAdId: string = GAMEDATA.interstitialAdId; | |
9 | + /** 插屏广告实例 */ | |
10 | + public static interstitialAd: any; | |
11 | + /** 插屏广告是否加载完成 */ | |
12 | + private static interstitialSuccell: boolean = false; | |
13 | + /** 初始化插屏广告 */ | |
14 | + public static initInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { | |
15 | + this.interstitialAdId = adUnitId; | |
16 | + this.createInterstitial(); | |
17 | + } | |
18 | 18 | |
19 | -// /** 显示插屏广告 */ | |
20 | -// public static showInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { | |
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 | -// }) | |
35 | -// } | |
19 | + /** 显示插屏广告 */ | |
20 | + public static showInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { | |
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 | + }) | |
35 | + } | |
36 | 36 | |
37 | -// /** 创建插屏广告 */ | |
38 | -// private static createInterstitial(isShow: boolean = false, resolve?) { | |
39 | -// LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.request) | |
40 | -// this.interstitialAd = AlipayApi.I.createInterstitialAd(this.interstitialAdId); | |
41 | -// this.interstitialAd.onLoad(async () => { | |
42 | -// AlipayInterstitial.interstitialSuccell = true; | |
43 | -// LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.rt) | |
44 | -// if (isShow) { | |
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 | -// AlipayInterstitial.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 | -// }) | |
53 | -// } | |
54 | -// }) | |
55 | -// this.interstitialAd.onError(err => { | |
56 | -// LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) | |
57 | -// AlipayInterstitial.interstitialSuccell = false; | |
58 | -// resolve && resolve({ code: err.errCode, msg: err.errMsg }); | |
59 | -// }) | |
37 | + /** 创建插屏广告 */ | |
38 | + private static createInterstitial(isShow: boolean = false, resolve?) { | |
39 | + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.request) | |
40 | + this.interstitialAd = AlipayApi.I.createInterstitialAd(this.interstitialAdId); | |
41 | + this.interstitialAd.onLoad(async () => { | |
42 | + AlipayInterstitial.interstitialSuccell = true; | |
43 | + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.rt) | |
44 | + if (isShow) { | |
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 | + AlipayInterstitial.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 | + }) | |
53 | + } | |
54 | + }) | |
55 | + this.interstitialAd.onError(err => { | |
56 | + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) | |
57 | + AlipayInterstitial.interstitialSuccell = false; | |
58 | + resolve && resolve({ code: err.errCode, msg: err.errMsg }); | |
59 | + }) | |
60 | 60 | |
61 | -// this.interstitialAd.onClose(call => { | |
62 | -// this.createInterstitial(false); | |
63 | -// }) | |
64 | -// // }).bind(this), 200); | |
61 | + this.interstitialAd.onClose(call => { | |
62 | + this.createInterstitial(false); | |
63 | + }) | |
64 | + // }).bind(this), 200); | |
65 | 65 | |
66 | 66 | |
67 | -// } | |
68 | -// } | |
69 | 67 | \ No newline at end of file |
68 | + } | |
69 | +} | |
70 | 70 | \ No newline at end of file | ... | ... |
wxsdk/alipay/zfbPay.ts
... | ... | @@ -1,183 +0,0 @@ |
1 | -import { WxHelper } from '../../../game/sdk/WxHelper'; | |
2 | -import { GAMEDATA } from '../base/SDKConst'; | |
3 | -import { EnvCode } from '../base/SDKEnum'; | |
4 | -import { SDKApi } from '../http/SDKApi'; | |
5 | -import DataService from '../service/DataService'; | |
6 | -import WxSystem from '../wx/WxSystem'; | |
7 | - | |
8 | -export default class ZfbPay { | |
9 | - /** | |
10 | - * 发起支付 | |
11 | - */ | |
12 | - pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}): Promise<any> { | |
13 | - return new Promise((resolve, reject) => { | |
14 | - let { Mode, OfferId, ZoneId, CurrencyType, Platform } = GAMEDATA.MidasPay; | |
15 | - // 环境配置,0:米大师正式环境 1:米大师沙箱环境 | |
16 | - let env = DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1; | |
17 | - // 平台类型,android or ios,config.js有配置走配置,否则判断系统id | |
18 | - let platform = DataService.I.Platform; | |
19 | - let pms = { | |
20 | - mode: Mode, | |
21 | - env, | |
22 | - platform, | |
23 | - offerId: OfferId, | |
24 | - currencyType: CurrencyType, | |
25 | - buyQuantity: params.money / 10, | |
26 | - zoneId: ZoneId | |
27 | - }; | |
28 | - let extend = ""; | |
29 | - for (let key in opts) { | |
30 | - extend += (`${key}=${opts[key]}&`) | |
31 | - } | |
32 | - extend = extend.substring(0, extend.length - 1); | |
33 | - extend = encodeURIComponent(extend); | |
34 | - | |
35 | - let payParams = { | |
36 | - ...this.buildParams(), | |
37 | - extend, | |
38 | - orderid: params.orderid, | |
39 | - // payid: params.payid, | |
40 | - goodid: params.goodid, | |
41 | - money: params.money, | |
42 | - platform | |
43 | - }; | |
44 | - SDKApi.zfbOrderReport(payParams).then(res => { | |
45 | - console.log("res:" + JSON.stringify(res)); | |
46 | - console.log("调用函数成功00"); | |
47 | - if (!res.code) { | |
48 | - let { customId, buyQuantity, extraInfo } = res.data; | |
49 | - my.requestGamePayment({ | |
50 | - customId, | |
51 | - buyQuantity, | |
52 | - extraInfo, | |
53 | - success(res) { | |
54 | - console.log("调用函数成功"); | |
55 | - resolve({ code: 0, msg: '支付成功!' }) | |
56 | - }, | |
57 | - fail(err) { | |
58 | - console.log("调用函数失败"); | |
59 | - if (err && err.error) { | |
60 | - if ("" + err.error == '15215') { | |
61 | - my.alert({ | |
62 | - title: '您好,基于国家新闻出版署《关于防止未成年人沉迷网络游戏的通知》的规定,支付宝限制未成年人游戏充值哦', | |
63 | - }); | |
64 | - } else if ("" + err.error == '15204') { | |
65 | - my.alert({ | |
66 | - title: '非常抱歉,充值功能暂不可用,请稍后再试', | |
67 | - }); | |
68 | - } | |
69 | - } | |
70 | - resolve({ code: err.errCode, msg: '支付失败' }); | |
71 | - }, | |
72 | - complete(res) { | |
73 | - try { | |
74 | - console.log(JSON.stringify(res)); | |
75 | - } catch (error) { | |
76 | - | |
77 | - } | |
78 | - console.log(res) | |
79 | - console.log("调用完成"); | |
80 | - }, | |
81 | - }) | |
82 | - } else { | |
83 | - console.log("调用函数成功222"); | |
84 | - reject(res); | |
85 | - } | |
86 | - }) | |
87 | - }); | |
88 | - } | |
89 | - | |
90 | - private async handlePaySuccess(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts: any, resolve: any, reject: any, t = 1000) { | |
91 | - let extend = ""; | |
92 | - for (let key in opts) { | |
93 | - extend += (`${key}=${opts[key]}&`) | |
94 | - } | |
95 | - extend = extend.substring(0, extend.length - 1); | |
96 | - extend = encodeURIComponent(extend); | |
97 | - let params = { | |
98 | - ...this.buildParams(), | |
99 | - extend, | |
100 | - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, | |
101 | - orderid: data.orderid, | |
102 | - payid: data.payid, goodid: data.goodid, | |
103 | - type: 1, | |
104 | - money: data.money, | |
105 | - platform: data.platform | |
106 | - }; | |
107 | - var that = this; | |
108 | - SDKApi.zfbOrderReport(params) | |
109 | - .then(res => { | |
110 | - if (!res.code) { | |
111 | - resolve(res); | |
112 | - } else { | |
113 | - t = Math.min(t * 2, 60000) | |
114 | - setTimeout(() => { | |
115 | - that.handlePaySuccess(data, opts, resolve, reject, t) | |
116 | - }, t); | |
117 | - } | |
118 | - }) | |
119 | - } | |
120 | - | |
121 | - private handlePayError(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts, err: any, reject: any) { | |
122 | - console.log("支付失败", JSON.stringify(err)); | |
123 | - let type = 2; | |
124 | - if (err.errCode + '' == '1') { | |
125 | - type = 3; | |
126 | - } | |
127 | - let extend = ""; | |
128 | - for (let key in opts) { | |
129 | - extend += (`${key}=${opts[key]}&`) | |
130 | - } | |
131 | - extend = extend.substring(0, extend.length - 1); | |
132 | - extend = encodeURIComponent(extend); | |
133 | - let params = { | |
134 | - ...this.buildParams(), | |
135 | - extend, | |
136 | - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, | |
137 | - orderid: data.orderid, | |
138 | - payid: data.payid, goodid: data.goodid, | |
139 | - type, | |
140 | - money: data.money, | |
141 | - platform: data.platform | |
142 | - }; | |
143 | - SDKApi.zfbOrderReport(params) | |
144 | - reject(err); | |
145 | - } | |
146 | - | |
147 | - /** | |
148 | - * 构建支付公用参数 | |
149 | - */ | |
150 | - private buildParams() { | |
151 | - let gameid = GAMEDATA.game_id; | |
152 | - let channel = DataService.I.ChannelId; | |
153 | - let openid = DataService.I.OpenId; | |
154 | - let brand = WxSystem.I.brand; | |
155 | - let model = WxSystem.I.model; | |
156 | - let version = WxSystem.I.version; | |
157 | - let system = WxSystem.I.system; | |
158 | - let sdkversion = WxSystem.I.SDKVersion; | |
159 | - let scene = DataService.I.Scene + ''; | |
160 | - let uid = DataService.I.UserId; | |
161 | - let token = DataService.I.Token; | |
162 | - let env = DataService.I.EnvEnum === 1 ? 'pre' : 'prod'; | |
163 | - return { | |
164 | - gameid, | |
165 | - openid, | |
166 | - channel, | |
167 | - brand, | |
168 | - model, | |
169 | - version, | |
170 | - system, | |
171 | - sdkversion, | |
172 | - scene, | |
173 | - uid, | |
174 | - token, | |
175 | - env | |
176 | - }; | |
177 | - } | |
178 | - | |
179 | - private static _instance: ZfbPay; | |
180 | - static get I(): ZfbPay { | |
181 | - return this._instance || (this._instance = new ZfbPay); | |
182 | - } | |
183 | -} | |
184 | 0 | \ No newline at end of file |
wxsdk/base/SDKBaseData.ts
wxsdk/base/SDKConst.ts
1 | 1 | // 游戏配置数据 只需要改动这里的配置信息 |
2 | +// 2021003184609526 | |
2 | 3 | export const GAMEDATA = { |
3 | - game_id: '10110',//游戏id | |
4 | + game_id: '10150',//游戏id | |
4 | 5 | isDebug: false, |
5 | - channel_id: '10110',//渠道id 暂时和游戏id一致 | |
6 | + channel_id: '10150',//渠道id 暂时和游戏id一致 | |
6 | 7 | version: '1.0.0', //版本号 中台控制正式还是测试服,尽量保持和小游戏版本一致 |
7 | - appkey: '48ef655c48f53f1e75f2108cf65d394e',//中台appkey | |
8 | - interstitialAdId: 'adunit-4bd19de3c351233e',//插屏ID | |
9 | - bannerId: 'adunit-6145b17777e308a8',//banner | |
10 | - customId: 'adunit-193590de82ede6a4',//原生模板单个 | |
11 | - videoAd: 'adunit-59404ef14e6c32ed',//初始化视频广告id | |
8 | + appkey: '761bdbb773c59e545ac729adec818ddc',//中台appkey | |
9 | + interstitialAdId: 'ad_tiny_2021004125691158_202311162200070802',//插屏ID | |
10 | + bannerId: 'ad_tiny_2021004125691158_202311162200070801',//banner | |
11 | + customId: '',//原生模板单个 | |
12 | + videoAd: 'ad_tiny_2021004125691158_202311162200070775',//初始化视频广告id | |
12 | 13 | shareMessageToFriend: { // 暂时只支持一个场景值 |
13 | 14 | scene: 0, //定向分享场景值1-50 配>0的会初始化 |
14 | 15 | sharekey: 'shareMessageToFriendScene',//定向分享对应后台的分享key |
15 | 16 | share_id: 26,//定向分享对应后台的分享key |
16 | 17 | }, |
17 | - default_share: { //默认分享数据在拉取不到中台分享数据的时候用 | |
18 | - content: '惊喜世界合不停',//分享标题 *找运营提供 | |
19 | - icon: 'https://cdn-wxsdk.miso-lab.com/7d/da1ed3fb6073ddd43f156f98c625e3.jpg',//分享图链接 *找运营提供 | |
20 | - id: '9999',//默认id 写死9999 | |
21 | - key: 'default',//默认分享key 写死default | |
22 | - title: '默认',//无需修改 | |
23 | - typ: 1,//分享类型 写死1 | |
24 | - videoid: '',//默认的视频广告id 填空就行 | |
18 | + default_share: { | |
19 | + content: '还记得童年的泡泡龙吗?一起来怀旧吧~ 这个可以不?', | |
20 | + icon: 'https://cdn-wxsdk.miso-lab.com/f0/5653094b6b7826c8afd813d12735e3.jpg', | |
21 | + id: '9999', | |
22 | + key: 'default', | |
23 | + title: '默认', | |
24 | + typ: 1, | |
25 | + videoid: '' | |
25 | 26 | }, |
26 | - MidasPay: { // 米大师虚拟支付配置 *找运营提供 | |
27 | - OfferId: "1450051274", // 在米大师申请的应用id *找运营提供 | |
28 | - ZoneId: "1", // 分区ID,默认:1 | |
29 | - Mode: "game", // 默认:game | |
30 | - CurrencyType: "CNY", // 默认:CNY | |
31 | - Platform: '' // 申请接入时的平台 | |
32 | - } | |
27 | + subscribeIds: ['yB-vq0DvOhazzDbvS1UzttLMIQ50Z_i0n8st6yEZYkw', '4al8p3UBb3xqn7TYN1J5wYtKrCbFc2MYESAv1vWi-C0'], //, 'cMo71MjAFzGM2MEpRw2p8T5jJaEhXJUfiIjoOB5oO70'], | |
28 | + versionContent: '1、开启每日幸运转盘活动\r\n2、针对部分玩家出现的卡顿问题进行修复' | |
33 | 29 | } |
34 | 30 | |
35 | 31 | // sdk版本 |
36 | -export const SDKVersion = 'v1.0.15'; | |
32 | +export const SDKVersion = 'v1.0.8'; | |
37 | 33 | // 是否打印 |
38 | 34 | export const __LOG__ = false; |
39 | 35 | // 是否mock |
... | ... | @@ -41,6 +37,8 @@ export var sdkEnv = { |
41 | 37 | isDebug: false |
42 | 38 | }; |
43 | 39 | |
40 | + | |
41 | + | |
44 | 42 | //游戏基础信息 |
45 | 43 | export const VersionHost = 'https://wxsdk-ver.d3games.com/version'; |
46 | 44 | |
... | ... | @@ -86,7 +84,6 @@ export const HostKeys = { |
86 | 84 | client_log: 'logstores/client_log/track', //客户端日志 |
87 | 85 | consume: 'logstores/consume/track', //资源上报 |
88 | 86 | daystay: 'logstores/daystay/track', //300s停留上报 |
89 | - loading: 'logstores/loading/track', //loading上报 | |
90 | 87 | |
91 | 88 | //登录 |
92 | 89 | Login: 'api/login', //登录 |
... | ... | @@ -102,27 +99,29 @@ export const HostKeys = { |
102 | 99 | rankAdd: 'api/rank/add', //排行榜添加分数 517废弃 |
103 | 100 | rankList: 'api/rank/list', //世界排行榜 517废弃 |
104 | 101 | totalrankAdd: 'game/totalrank/add', //排行榜添加分数 |
105 | - totalrankList: 'game/totalrank/list', //世界排行榜 | |
102 | + totalrankList: 'game/totalrank/list', //世界排行榜 | |
103 | + sendsubscribe: 'api/subscribe/event', //订阅 | |
106 | 104 | adList: 'api/adplan/list', //广告计划列表 |
105 | + notice: 'game/notice/info', //公告 | |
107 | 106 | behavior: 'api/douyin/behavior', //抖音投放关键行为 |
108 | 107 | attribute: 'api/member/attribute/set', //修改用户属性 |
109 | - wxencrypted: 'api/wx/encrypted', | |
110 | 108 | checkmsg: 'api/wx/checkmsg', //检测文本 |
111 | 109 | updateNickname: 'api/member/update/nickname',//更改用户昵称头像 |
110 | + wxencrypted: 'api/wx/encrypted', | |
112 | 111 | |
113 | 112 | //订单 |
114 | - orderReport: 'api/order/v2/mimas/new', //wx订单信息上报 | |
115 | - orderQuery: 'api/order/query', //订单信息查询 | |
116 | - preorder: 'api/order/v2/preorder', //获取支付方式 | |
117 | - bytedanceOrderReport: 'api/order/v2/bytedance', //字节订单信息上报 | |
118 | - qqOrderReport: 'api/order/v2/qq', //qq订单信息上报 | |
119 | - zfbOrderReport:'api/order/v2/zfb/add', //支付宝小游戏订单上报 | |
113 | + orderReport: 'api/order/v2/mimas/new', //订单信息上报 | |
114 | + orderQuery: 'api/order/query', //订单信息查询 | |
115 | + preorder: 'api/order/v2/preorder', //获取支付方式 | |
120 | 116 | // |
121 | 117 | goodslist: 'api/v2/goodslist', //商品列表 |
122 | 118 | |
123 | 119 | |
124 | - //支付宝 | |
125 | - AlipayIncrementGameaction: 'api/ali/action/submit' ,//玩一玩:增量游戏行为完成上报 | |
120 | + aliMission: 'api/ali/action/submit',//阿里玩一玩增量任务 | |
121 | + alipayIntergralBuy: 'api/ali/point/pay',//支付宝会员积分购买 | |
122 | + alipayIntergralAuth: 'api/ali/point/auth',//支付宝会员积分授权 | |
123 | + alipayIntergralQuery: 'api/ali/point/query',//支付宝会员积分查询 | |
124 | + isAddHomePage: 'api/ali/homepage/consult',//玩一玩小程序是否已加首咨询 | |
126 | 125 | }; |
127 | 126 | |
128 | 127 | // 本地存储keys | ... | ... |
... | ... | @@ -0,0 +1,230 @@ |
1 | + | |
2 | +/** 返回参数类型 */ | |
3 | +interface IResult<T> { | |
4 | + /** 错误码 */ | |
5 | + code?: number; | |
6 | + /** 错误信息 */ | |
7 | + msg?: string; | |
8 | + /** 返回数据 */ | |
9 | + data?: T; | |
10 | + /** 服务器时间 */ | |
11 | + servertime?: number; | |
12 | +} | |
13 | + | |
14 | +/** 微信api 返回用户信息 */ | |
15 | +interface WxUserInfo { | |
16 | + /** 用户昵称 */ | |
17 | + nickName: string; | |
18 | + /** 用户头像图片的 URL。URL 最后一个数值代表正方形头像大小 | |
19 | + * (有 0、46、64、96、132 数值可选,0 代表 640x640 的正方形头像,46 表示 46x46 的正方形头像, | |
20 | + * 剩余数值以此类推。默认132),用户没有头像时该项为空。若用户更换头像,原有头像 URL 将失效。 */ | |
21 | + avatarUrl: string; | |
22 | + /** 用户性别 gender的合法值(0未知,1男性,2女性) */ | |
23 | + gender: number; | |
24 | + /** 用户所在国家 */ | |
25 | + country: string; | |
26 | + /** 用户所在省份 */ | |
27 | + province: string; | |
28 | + /** 用户所在城市 */ | |
29 | + city: string; | |
30 | + /** 显示 country,province,city 所用的语言(en英文,zh_CN简体中文,zh_TW繁体中文) */ | |
31 | + language: string; | |
32 | +} | |
33 | + | |
34 | +/** 显示模态对话框参数类型 */ | |
35 | +interface ShowModalType { | |
36 | + /** 提示的标题 */ | |
37 | + title: string; | |
38 | + /** 提示的内容 */ | |
39 | + content: string; | |
40 | + /** 是否显示取消按钮 */ | |
41 | + showCancel?: boolean; | |
42 | + /** 取消按钮的文字,最多 4 个字符 */ | |
43 | + cancelText?: string; | |
44 | + /** 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串 */ | |
45 | + cancelColor?: string; | |
46 | + /** 确认按钮的文字,最多 4 个字符 */ | |
47 | + confirmText?: string; | |
48 | + /** 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串 */ | |
49 | + confirmColor?: string; | |
50 | + /** 接口调用成功的回调函数 */ | |
51 | + success?: (res: { confirm: boolean, cancel: boolean }) => void; | |
52 | + /** 接口调用失败的回调函数 */ | |
53 | + fail?: () => void; | |
54 | + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ | |
55 | + complete?: () => void; | |
56 | +} | |
57 | +/** | |
58 | + * 排行榜数据 | |
59 | + */ | |
60 | +interface IRankData { | |
61 | + fraction: number, // 对应type传入的分数、数量或者其他 | |
62 | + headurl: string, //头像 | |
63 | + nickname: string,//昵称 | |
64 | + uid: number//用户id | |
65 | + rankData: any //扩展参数 | |
66 | +} | |
67 | + | |
68 | +interface _NetworkTypeSuccessObject { | |
69 | + networkType: string; // wifi/2g/3g/4g/unknown(Android 下不常见的网络类型)/none(无网络) | |
70 | +} | |
71 | +interface _StyleObject { | |
72 | + left?: number; | |
73 | + | |
74 | + top?: number; | |
75 | + | |
76 | + width?: number; | |
77 | + | |
78 | + height?: number; | |
79 | +} | |
80 | +interface _StyleGameObject { | |
81 | + left?: number; | |
82 | + top?: number; | |
83 | +} | |
84 | + | |
85 | +interface _BannerAdObject { | |
86 | + adUnitId: string; | |
87 | + adIntervals?: number; | |
88 | + style: _StyleObject; | |
89 | +} | |
90 | +interface _FeedbackButtonObject { | |
91 | + /** | |
92 | + * 按钮的类型 | |
93 | + */ | |
94 | + type: string; | |
95 | + | |
96 | + /** | |
97 | + * 按钮上的文本,仅当 type 为 text 时有效 | |
98 | + */ | |
99 | + text?: string; | |
100 | + | |
101 | + /** | |
102 | + * 按钮的背景图片,仅当 type 为 image 时有效 | |
103 | + */ | |
104 | + image?: string; | |
105 | + | |
106 | + /** | |
107 | + * 按钮的样式 | |
108 | + */ | |
109 | + style: _ButtonStyle; | |
110 | +} | |
111 | + | |
112 | +interface _UserInfoButton { | |
113 | + type: string; | |
114 | + | |
115 | + text: string; | |
116 | + | |
117 | + image: string; | |
118 | + | |
119 | + style: _ButtonStyle; | |
120 | + | |
121 | + show: Function; | |
122 | + | |
123 | + hide: Function; | |
124 | + | |
125 | + destroy: Function; | |
126 | + | |
127 | + onTap: (callback: Function) => void; | |
128 | + | |
129 | + offTap: (callback: Function) => void; | |
130 | +} | |
131 | + | |
132 | +interface _ShareAppMessageObject { | |
133 | + /** | |
134 | + * 是否使用带 shareTicket 的转发详情 | |
135 | + */ | |
136 | + withShareTicket?: boolean; | |
137 | + /** | |
138 | + * 发标题,不传则默认使用当前小游戏的昵称。 | |
139 | + */ | |
140 | + title?: string; | |
141 | + | |
142 | + /** | |
143 | + * 转发显示图片的链接,可以是网络图片路径或本地图片文件路径或相对代码包根目录的图片文件路径。显示图片长宽比是 5: 4 | |
144 | + */ | |
145 | + imageUrl?: string; | |
146 | + | |
147 | + /** | |
148 | + * 查询字符串,必须是 key1 = val1 & key2=val2 的格式。从这条转发消息进入后,可通过 wx.getLaunchOptionSync() 或 wx.onShow() 获取启动参数中的 query。 | |
149 | + */ | |
150 | + query?: string; | |
151 | + | |
152 | + /** | |
153 | + * 审核通过的图片 ID,详见 使用审核通过的转发图片 | |
154 | + */ | |
155 | + imageUrlId?: string; | |
156 | + | |
157 | + /** | |
158 | + * 10.10后废弃 | |
159 | + */ | |
160 | + success?: (ret?: any) => void; | |
161 | + | |
162 | + /** | |
163 | + * 接口调用失败的回调函数 | |
164 | + */ | |
165 | + fail?: (err?: any) => void; | |
166 | + | |
167 | + /** | |
168 | + * 接口调用结束的回调函数(调用成功、失败都会执行) | |
169 | + */ | |
170 | + complete?: () => void; | |
171 | + | |
172 | + /** | |
173 | + * 接口取消的回调 | |
174 | + */ | |
175 | + cancel?: () => void; | |
176 | +} | |
177 | +interface _UpdateShareMenuObject { | |
178 | + /** | |
179 | + * 是否使用带 shareTicket 的转发 | |
180 | + */ | |
181 | + withShareTicket?: boolean; | |
182 | + | |
183 | + /** | |
184 | + * 接口调用成功的回调函数 | |
185 | + */ | |
186 | + success?: () => void; | |
187 | + | |
188 | + /** | |
189 | + * 接口调用失败的回调函数 | |
190 | + */ | |
191 | + fail?: () => void; | |
192 | + | |
193 | + /** | |
194 | + * 接口调用结束的回调函数(调用成功、失败都会执行) | |
195 | + */ | |
196 | + complete?: () => void; | |
197 | + | |
198 | + /** | |
199 | + * 接口取消的回调 | |
200 | + */ | |
201 | + cancel?: () => void; | |
202 | +} | |
203 | +interface _getShareInfoSuccessObject { | |
204 | + /** | |
205 | + * 错误信息 | |
206 | + */ | |
207 | + errMsg: string; | |
208 | + | |
209 | + /** | |
210 | + * 包括敏感数据在内的完整转发信息的加密数据,详细见[加密数据解密算法](./signature.md#加密数据解密算法) | |
211 | + */ | |
212 | + encryptedData: string; | |
213 | + | |
214 | + /** | |
215 | + * 加密算法的初始向量,详细见[加密数据解密算法](./signature.md#加密数据解密算法) | |
216 | + */ | |
217 | + iv: string; | |
218 | +} | |
219 | + | |
220 | + | |
221 | +interface IGameList { | |
222 | + id: number,//唯一id | |
223 | + appid: string,//微信appid | |
224 | + path: string, //携带参数 | |
225 | + icon: string, //游戏icon | |
226 | + game: string //游戏名称 | |
227 | + adtyp: string,//类型 | |
228 | + animation: string,//骨骼 | |
229 | + highlight: string,//是否高亮 | |
230 | +} | ... | ... |
wxsdk/base/SDKDefault.ts
... | ... | @@ -1,230 +0,0 @@ |
1 | - | |
2 | -/** 返回参数类型 */ | |
3 | -interface IResult<T> { | |
4 | - /** 错误码 */ | |
5 | - code?: number; | |
6 | - /** 错误信息 */ | |
7 | - msg?: string; | |
8 | - /** 返回数据 */ | |
9 | - data?: T; | |
10 | - /** 服务器时间 */ | |
11 | - servertime?: number; | |
12 | -} | |
13 | - | |
14 | -/** 微信api 返回用户信息 */ | |
15 | -interface WxUserInfo { | |
16 | - /** 用户昵称 */ | |
17 | - nickName: string; | |
18 | - /** 用户头像图片的 URL。URL 最后一个数值代表正方形头像大小 | |
19 | - * (有 0、46、64、96、132 数值可选,0 代表 640x640 的正方形头像,46 表示 46x46 的正方形头像, | |
20 | - * 剩余数值以此类推。默认132),用户没有头像时该项为空。若用户更换头像,原有头像 URL 将失效。 */ | |
21 | - avatarUrl: string; | |
22 | - /** 用户性别 gender的合法值(0未知,1男性,2女性) */ | |
23 | - gender: number; | |
24 | - /** 用户所在国家 */ | |
25 | - country: string; | |
26 | - /** 用户所在省份 */ | |
27 | - province: string; | |
28 | - /** 用户所在城市 */ | |
29 | - city: string; | |
30 | - /** 显示 country,province,city 所用的语言(en英文,zh_CN简体中文,zh_TW繁体中文) */ | |
31 | - language: string; | |
32 | -} | |
33 | - | |
34 | -/** 显示模态对话框参数类型 */ | |
35 | -interface ShowModalType { | |
36 | - /** 提示的标题 */ | |
37 | - title: string; | |
38 | - /** 提示的内容 */ | |
39 | - content: string; | |
40 | - /** 是否显示取消按钮 */ | |
41 | - showCancel?: boolean; | |
42 | - /** 取消按钮的文字,最多 4 个字符 */ | |
43 | - cancelText?: string; | |
44 | - /** 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串 */ | |
45 | - cancelColor?: string; | |
46 | - /** 确认按钮的文字,最多 4 个字符 */ | |
47 | - confirmText?: string; | |
48 | - /** 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串 */ | |
49 | - confirmColor?: string; | |
50 | - /** 接口调用成功的回调函数 */ | |
51 | - success?: (res: { confirm: boolean, cancel: boolean }) => void; | |
52 | - /** 接口调用失败的回调函数 */ | |
53 | - fail?: () => void; | |
54 | - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ | |
55 | - complete?: () => void; | |
56 | -} | |
57 | -/** | |
58 | - * 排行榜数据 | |
59 | - */ | |
60 | -interface IRankData { | |
61 | - fraction: number, // 对应type传入的分数、数量或者其他 | |
62 | - headurl: string, //头像 | |
63 | - nickname: string,//昵称 | |
64 | - uid: number//用户id | |
65 | - rankData: any //扩展参数 | |
66 | -} | |
67 | - | |
68 | -interface _NetworkTypeSuccessObject { | |
69 | - networkType: string; // wifi/2g/3g/4g/unknown(Android 下不常见的网络类型)/none(无网络) | |
70 | -} | |
71 | -interface _StyleObject { | |
72 | - left?: number; | |
73 | - | |
74 | - top?: number; | |
75 | - | |
76 | - width?: number; | |
77 | - | |
78 | - height?: number; | |
79 | -} | |
80 | -interface _StyleGameObject { | |
81 | - left?: number; | |
82 | - top?: number; | |
83 | -} | |
84 | - | |
85 | -interface _BannerAdObject { | |
86 | - adUnitId: string; | |
87 | - adIntervals?: number; | |
88 | - style: _StyleObject; | |
89 | -} | |
90 | -interface _FeedbackButtonObject { | |
91 | - /** | |
92 | - * 按钮的类型 | |
93 | - */ | |
94 | - type: string; | |
95 | - | |
96 | - /** | |
97 | - * 按钮上的文本,仅当 type 为 text 时有效 | |
98 | - */ | |
99 | - text?: string; | |
100 | - | |
101 | - /** | |
102 | - * 按钮的背景图片,仅当 type 为 image 时有效 | |
103 | - */ | |
104 | - image?: string; | |
105 | - | |
106 | - /** | |
107 | - * 按钮的样式 | |
108 | - */ | |
109 | - style: _ButtonStyle; | |
110 | -} | |
111 | - | |
112 | -interface _UserInfoButton { | |
113 | - type: string; | |
114 | - | |
115 | - text: string; | |
116 | - | |
117 | - image: string; | |
118 | - | |
119 | - style: _ButtonStyle; | |
120 | - | |
121 | - show: Function; | |
122 | - | |
123 | - hide: Function; | |
124 | - | |
125 | - destroy: Function; | |
126 | - | |
127 | - onTap: (callback: Function) => void; | |
128 | - | |
129 | - offTap: (callback: Function) => void; | |
130 | -} | |
131 | - | |
132 | -interface _ShareAppMessageObject { | |
133 | - /** | |
134 | - * 是否使用带 shareTicket 的转发详情 | |
135 | - */ | |
136 | - withShareTicket?: boolean; | |
137 | - /** | |
138 | - * 发标题,不传则默认使用当前小游戏的昵称。 | |
139 | - */ | |
140 | - title?: string; | |
141 | - | |
142 | - /** | |
143 | - * 转发显示图片的链接,可以是网络图片路径或本地图片文件路径或相对代码包根目录的图片文件路径。显示图片长宽比是 5: 4 | |
144 | - */ | |
145 | - imageUrl?: string; | |
146 | - | |
147 | - /** | |
148 | - * 查询字符串,必须是 key1 = val1 & key2=val2 的格式。从这条转发消息进入后,可通过 wx.getLaunchOptionSync() 或 wx.onShow() 获取启动参数中的 query。 | |
149 | - */ | |
150 | - query?: string; | |
151 | - | |
152 | - /** | |
153 | - * 审核通过的图片 ID,详见 使用审核通过的转发图片 | |
154 | - */ | |
155 | - imageUrlId?: string; | |
156 | - | |
157 | - /** | |
158 | - * 10.10后废弃 | |
159 | - */ | |
160 | - success?: (ret?: any) => void; | |
161 | - | |
162 | - /** | |
163 | - * 接口调用失败的回调函数 | |
164 | - */ | |
165 | - fail?: (err?: any) => void; | |
166 | - | |
167 | - /** | |
168 | - * 接口调用结束的回调函数(调用成功、失败都会执行) | |
169 | - */ | |
170 | - complete?: () => void; | |
171 | - | |
172 | - /** | |
173 | - * 接口取消的回调 | |
174 | - */ | |
175 | - cancel?: () => void; | |
176 | -} | |
177 | -interface _UpdateShareMenuObject { | |
178 | - /** | |
179 | - * 是否使用带 shareTicket 的转发 | |
180 | - */ | |
181 | - withShareTicket?: boolean; | |
182 | - | |
183 | - /** | |
184 | - * 接口调用成功的回调函数 | |
185 | - */ | |
186 | - success?: () => void; | |
187 | - | |
188 | - /** | |
189 | - * 接口调用失败的回调函数 | |
190 | - */ | |
191 | - fail?: () => void; | |
192 | - | |
193 | - /** | |
194 | - * 接口调用结束的回调函数(调用成功、失败都会执行) | |
195 | - */ | |
196 | - complete?: () => void; | |
197 | - | |
198 | - /** | |
199 | - * 接口取消的回调 | |
200 | - */ | |
201 | - cancel?: () => void; | |
202 | -} | |
203 | -interface _getShareInfoSuccessObject { | |
204 | - /** | |
205 | - * 错误信息 | |
206 | - */ | |
207 | - errMsg: string; | |
208 | - | |
209 | - /** | |
210 | - * 包括敏感数据在内的完整转发信息的加密数据,详细见[加密数据解密算法](./signature.md#加密数据解密算法) | |
211 | - */ | |
212 | - encryptedData: string; | |
213 | - | |
214 | - /** | |
215 | - * 加密算法的初始向量,详细见[加密数据解密算法](./signature.md#加密数据解密算法) | |
216 | - */ | |
217 | - iv: string; | |
218 | -} | |
219 | - | |
220 | - | |
221 | -interface IGameList { | |
222 | - id: number,//唯一id | |
223 | - appid: string,//微信appid | |
224 | - path: string, //携带参数 | |
225 | - icon: string, //游戏icon | |
226 | - game: string //游戏名称 | |
227 | - adtyp: string,//类型 | |
228 | - animation: string,//骨骼 | |
229 | - highlight: string,//是否高亮 | |
230 | -} |
wxsdk/base/wx.d.ts
wxsdk/douyin/DouyinInterstitial.ts
... | ... | @@ -1,43 +0,0 @@ |
1 | -import { GAMEDATA } from "../base/SDKConst"; | |
2 | - | |
3 | -export default class DouyinInterstitial { | |
4 | - /** 插屏广告ID */ | |
5 | - private static interstitialAdId: string = GAMEDATA.interstitialAdId; | |
6 | - /** 插屏广告实例 */ | |
7 | - public static interstitialAd: any; | |
8 | - /** 插屏广告是否加载完成 */ | |
9 | - private static interstitialSuccell: boolean = false; | |
10 | - /** 初始化插屏广告 */ | |
11 | - public static initInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { | |
12 | - // this.interstitialAdId = adUnitId; | |
13 | - // this.createInterstitial(); | |
14 | - } | |
15 | - | |
16 | - private static canReTry = false; | |
17 | - /** 显示插屏广告 */ | |
18 | - public static showInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { | |
19 | - const interstitiaAd = tt.createInterstitialAd({ adUnitId: this.interstitialAdId }); | |
20 | - this.canReTry = true; | |
21 | - let onLoadHandle = ()=> { | |
22 | - console.log("插屏广告onload成功") | |
23 | - interstitiaAd.show().then(() => { | |
24 | - console.log("插屏广告展示成功"); | |
25 | - }); | |
26 | - } | |
27 | - interstitiaAd.onLoad(onLoadHandle); //创建会自动load | |
28 | - | |
29 | - let onErrorHandle = (err)=>{ | |
30 | - // 这里要等待一定时间后,或者等待下次需要展示的时候,参考频控,尝试一次,或者几次,不能一直尝试。 | |
31 | - if (this.canReTry) { | |
32 | - this.canReTry = false; | |
33 | - interstitiaAd.load(); //如果需要,这里等待一定时间后,或者等待下次需要展示的时候,再次 load->onLoad-> show。 | |
34 | - } else { | |
35 | - tt.showToast({ | |
36 | - title: "暂无广告", | |
37 | - icon: "none", | |
38 | - }); | |
39 | - } | |
40 | - } | |
41 | - interstitiaAd.onError(onErrorHandle); // 自动load 的失败会走到这里 | |
42 | - } | |
43 | -} | |
44 | 0 | \ No newline at end of file |
wxsdk/douyin/DouyinPay.ts
... | ... | @@ -1,175 +0,0 @@ |
1 | -import { GAMEDATA } from '../base/SDKConst'; | |
2 | -import { EnvCode } from '../base/SDKEnum'; | |
3 | -import { SDKApi } from '../http/SDKApi'; | |
4 | -import DataService from '../service/DataService'; | |
5 | -import WxSystem from '../wx/WxSystem'; | |
6 | - | |
7 | -export default class DouyinPay { | |
8 | - /** | |
9 | - * 发起支付 | |
10 | - */ | |
11 | - pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}): Promise<any> { | |
12 | - return new Promise((resolve, reject) => { | |
13 | - let { Mode, OfferId, ZoneId, CurrencyType, Platform } = GAMEDATA.MidasPay; | |
14 | - // 环境配置,0:米大师正式环境 1:米大师沙箱环境 | |
15 | - let env = DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1; | |
16 | - // 平台类型,android or ios,config.js有配置走配置,否则判断系统id | |
17 | - let platform = DataService.I.Platform; | |
18 | - let pms = { | |
19 | - mode: Mode, | |
20 | - env, | |
21 | - platform, | |
22 | - offerId: OfferId, | |
23 | - currencyType: CurrencyType, | |
24 | - buyQuantity: params.money / 10, | |
25 | - zoneId: ZoneId | |
26 | - }; | |
27 | - let extend = ""; | |
28 | - for (let key in opts) { | |
29 | - extend += (`${key}=${opts[key]}&`) | |
30 | - } | |
31 | - extend = extend.substring(0, extend.length - 1); | |
32 | - extend = encodeURIComponent(extend); | |
33 | - | |
34 | - let payParams = { | |
35 | - ...this.buildParams(), | |
36 | - extend, | |
37 | - orderid: params.orderid, | |
38 | - // payid: params.payid, | |
39 | - goodid: params.goodid, | |
40 | - money: params.money, | |
41 | - platform | |
42 | - }; | |
43 | - console.log("payParams", payParams); | |
44 | - SDKApi.bytedanceOrderReport(payParams).then(res => { | |
45 | - console.log("res", res); | |
46 | - if (!res.code) { | |
47 | - let { mode, env, currencyType, platform, buyQuantity, zoneId, customId, extraInfo } = res.data; | |
48 | - tt.requestGamePayment({ | |
49 | - mode, // 支付类型 | |
50 | - env, //支付环境 | |
51 | - currencyType, // 币种:目前仅为 "CNY" | |
52 | - platform, // 申请接入时的平台:目前仅为"android" | |
53 | - buyQuantity, // 购买数量,必须满足:金币数量*金币单价 = 限定价格等级(详见金币限定等级) | |
54 | - zoneId, | |
55 | - customId,//开发者自定义唯一订单号。如不填,支付结果回调将不包含此字段,将导致游戏开发者无法发放游戏道具, 基础库版本低于1.55.0没有此字段 | |
56 | - extraInfo,//extraInfo要转成字符串 | |
57 | - success(res) { | |
58 | - // console.log("调用函数成功", res); | |
59 | - resolve({ code: 0, msg: '支付成功!' }) | |
60 | - }, | |
61 | - fail(err) { | |
62 | - // console.log("调用函数失败", res); | |
63 | - resolve({ code: err.errCode, msg: '支付失败' }); | |
64 | - }, | |
65 | - complete(res) { | |
66 | - // console.log("调用完成", res); | |
67 | - }, | |
68 | - }) | |
69 | - // tt.requestGamePayment(pms) | |
70 | - // .then(() => this.handlePaySuccess({ ...params, platform }, opts, resolve, reject)) | |
71 | - // .catch(err => this.handlePayError({ ...params, platform }, opts, err, reject)); | |
72 | - } else { | |
73 | - reject(res); | |
74 | - } | |
75 | - }) | |
76 | - }); | |
77 | - } | |
78 | - | |
79 | - private async handlePaySuccess(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts: any, resolve: any, reject: any, t = 1000) { | |
80 | - // let code = await WxApi.I.login(); | |
81 | - | |
82 | - let extend = ""; | |
83 | - for (let key in opts) { | |
84 | - extend += (`${key}=${opts[key]}&`) | |
85 | - } | |
86 | - extend = extend.substring(0, extend.length - 1); | |
87 | - extend = encodeURIComponent(extend); | |
88 | - let params = { | |
89 | - ...this.buildParams(), | |
90 | - extend, | |
91 | - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, | |
92 | - orderid: data.orderid, | |
93 | - payid: data.payid, goodid: data.goodid, | |
94 | - type: 1, | |
95 | - money: data.money, | |
96 | - platform: data.platform | |
97 | - }; | |
98 | - var that = this; | |
99 | - SDKApi.bytedanceOrderReport(params) | |
100 | - .then(res => { | |
101 | - if (!res.code) { | |
102 | - resolve(res); | |
103 | - } else { | |
104 | - t = Math.min(t * 2, 60000) | |
105 | - // console.error("上报失败,重新上报", t) | |
106 | - setTimeout(() => { | |
107 | - that.handlePaySuccess(data, opts, resolve, reject, t) | |
108 | - }, t); | |
109 | - } | |
110 | - }) | |
111 | - } | |
112 | - | |
113 | - private handlePayError(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts, err: any, reject: any) { | |
114 | - console.log("支付失败", JSON.stringify(err)); | |
115 | - let type = 2; | |
116 | - if (err.errCode + '' == '1') { | |
117 | - type = 3; | |
118 | - } | |
119 | - let extend = ""; | |
120 | - for (let key in opts) { | |
121 | - extend += (`${key}=${opts[key]}&`) | |
122 | - } | |
123 | - extend = extend.substring(0, extend.length - 1); | |
124 | - extend = encodeURIComponent(extend); | |
125 | - let params = { | |
126 | - ...this.buildParams(), | |
127 | - extend, | |
128 | - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, | |
129 | - orderid: data.orderid, | |
130 | - payid: data.payid, goodid: data.goodid, | |
131 | - type, | |
132 | - money: data.money, | |
133 | - platform: data.platform | |
134 | - }; | |
135 | - SDKApi.bytedanceOrderReport(params) | |
136 | - reject(err); | |
137 | - } | |
138 | - | |
139 | - /** | |
140 | - * 构建支付公用参数 | |
141 | - */ | |
142 | - private buildParams() { | |
143 | - let gameid = GAMEDATA.game_id; | |
144 | - let channel = DataService.I.ChannelId; | |
145 | - let openid = DataService.I.OpenId; | |
146 | - let brand = WxSystem.I.brand; | |
147 | - let model = WxSystem.I.model; | |
148 | - let version = WxSystem.I.version; | |
149 | - let system = WxSystem.I.system; | |
150 | - let sdkversion = WxSystem.I.SDKVersion; | |
151 | - let scene = DataService.I.Scene + ''; | |
152 | - let uid = DataService.I.UserId; | |
153 | - let token = DataService.I.Token; | |
154 | - let env = DataService.I.EnvEnum === 1 ? 'pre' : 'prod'; | |
155 | - return { | |
156 | - gameid, | |
157 | - openid, | |
158 | - channel, | |
159 | - brand, | |
160 | - model, | |
161 | - version, | |
162 | - system, | |
163 | - sdkversion, | |
164 | - scene, | |
165 | - uid, | |
166 | - token, | |
167 | - env | |
168 | - }; | |
169 | - } | |
170 | - | |
171 | - private static _instance: DouyinPay; | |
172 | - static get I(): DouyinPay { | |
173 | - return this._instance || (this._instance = new DouyinPay); | |
174 | - } | |
175 | -} | |
176 | 0 | \ No newline at end of file |
wxsdk/http/SDKApi.ts
... | ... | @@ -9,10 +9,13 @@ export class SDKApi { |
9 | 9 | |
10 | 10 | //GameApi |
11 | 11 | public static ShareList = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.ShareList, ...args); |
12 | + public static notice = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.notice, ...args); | |
12 | 13 | |
13 | 14 | public static getConfig = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.getConfig, ...args); |
14 | 15 | //订阅 |
15 | 16 | public static subscribe = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.subscribe, ...args); |
17 | + public static sendsubscribe = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.sendsubscribe, ...args); | |
18 | + | |
16 | 19 | // |
17 | 20 | public static saveData = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.saveData, ...args); |
18 | 21 | public static getData = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.getData, ...args); |
... | ... | @@ -30,18 +33,17 @@ export class SDKApi { |
30 | 33 | public static behavior = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.behavior, ...args); |
31 | 34 | //修改用户属性 |
32 | 35 | public static attribute = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.attribute, ...args); |
33 | - // 解密关系链互动数据 | |
34 | - public static wxencrypted = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.wxencrypted, ...args); | |
35 | 36 | // 文本检测 |
36 | 37 | public static checkmsg = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.checkmsg, ...args); |
37 | - // | |
38 | - public static updateNickname = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.updateNickname, ...args); | |
39 | 38 | //LoginApi |
40 | 39 | public static Login = (...args) => SDKHttp.httpPost(DataService.I.LoginApi, HostKeys.Login, ...args); |
41 | 40 | |
42 | 41 | public static reftoken = (...args) => SDKHttp.httpPost(DataService.I.LoginApi, HostKeys.Reftoken, ...args); |
43 | 42 | |
44 | 43 | public static weakLogin = (...args) => SDKHttp.httpPost(DataService.I.LoginApi, HostKeys.weakLogin, ...args); |
44 | + public static updateNickname = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.updateNickname, ...args); | |
45 | + // 解密关系链互动数据 | |
46 | + public static wxencrypted = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.wxencrypted, ...args); | |
45 | 47 | |
46 | 48 | |
47 | 49 | //DotApi |
... | ... | @@ -72,28 +74,31 @@ export class SDKApi { |
72 | 74 | public static client_log = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.client_log, ...args); |
73 | 75 | |
74 | 76 | public static consume = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.consume, ...args); |
75 | - | |
77 | + | |
76 | 78 | public static daystay = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.daystay, ...args); |
77 | - | |
78 | - public static loading = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.loading, ...args); | |
79 | 79 | |
80 | 80 | |
81 | 81 | // OrderApi |
82 | 82 | public static pay = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderReport, ...args); |
83 | - public static bytedanceOrderReport = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.bytedanceOrderReport, ...args); | |
84 | - public static qqOrderReport = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.qqOrderReport, ...args); | |
85 | 83 | public static orderQuery = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderQuery, ...args); |
86 | 84 | public static preorder = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.preorder, ...args); |
87 | - public static zfbOrderReport = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.zfbOrderReport, ...args); | |
88 | - | |
85 | + | |
89 | 86 | public static goodslist = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.goodslist, ...args); |
90 | 87 | |
91 | 88 | |
92 | - //支付宝 | |
93 | - /** | |
94 | - * 玩一玩增量行为 | |
95 | - * @param args | |
96 | - * @returns | |
97 | - */ | |
98 | - public static incrementGameaction = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.AlipayIncrementGameaction, ...args); | |
89 | + | |
90 | + //阿里增量任务 | |
91 | + public static aliMission = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.aliMission, ...args); | |
92 | + | |
93 | + //支付宝会员授权查询 | |
94 | + public static alipayIntergralAuth = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.alipayIntergralAuth, ...args); | |
95 | + | |
96 | + //支付宝积分查询 | |
97 | + public static alipayIntergralQuery = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.alipayIntergralQuery, ...args); | |
98 | + //支付宝积分购买 | |
99 | + public static alipayIntergralBuy = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.alipayIntergralBuy, ...args); | |
100 | + | |
101 | + | |
102 | + //玩一玩小程序是否已加首咨询 | |
103 | + public static isAddHomePage = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.isAddHomePage, ...args); | |
99 | 104 | } | ... | ... |
wxsdk/http/SDKHttp.ts
... | ... | @@ -21,7 +21,7 @@ export default class SDKHttp { |
21 | 21 | if (data && typeof data === "object") { |
22 | 22 | data = JSON.stringify(data); |
23 | 23 | } |
24 | - // console.error("sign", url, JSON.stringify(data)) | |
24 | + console.error("sign"+ url+JSON.stringify(data)) | |
25 | 25 | data = data || ""; |
26 | 26 | if (method == "GET" && data != "") { |
27 | 27 | data = JSON.parse(data); |
... | ... | @@ -38,7 +38,7 @@ export default class SDKHttp { |
38 | 38 | if (xhr.readyState == 4) { |
39 | 39 | if (xhr.status >= 200 && xhr.status < 400) { |
40 | 40 | let responseText: any = xhr.responseText; |
41 | - // cc.log("responseText", responseText) | |
41 | + cc.log("responseText"+ responseText) | |
42 | 42 | try { |
43 | 43 | responseText = JSON.parse(responseText); |
44 | 44 | // cc.log("responseText22", responseText) |
... | ... | @@ -54,31 +54,39 @@ export default class SDKHttp { |
54 | 54 | return; |
55 | 55 | } |
56 | 56 | } else { |
57 | - console.error(xhr.status, '网络请求失败!'); | |
58 | - resolve({ code: -2 }); | |
57 | + // console.error(xhr.status, '网络请求失败!'); | |
58 | + resolve({ code: -5 }); | |
59 | 59 | } |
60 | 60 | } |
61 | 61 | }; |
62 | 62 | |
63 | 63 | xhr.ontimeout = function (info): void { |
64 | 64 | // cc.error("info1", info) |
65 | - resolve({ msg: `请求超时!`, code: -3 }); | |
65 | + resolve({ msg: `请求超时!`, code: -2 }); | |
66 | 66 | } |
67 | 67 | xhr.onerror = function (info): void { |
68 | 68 | // cc.error("info2", info) |
69 | - resolve({ msg: `请求失败!`, code: -4 }); | |
69 | + resolve({ msg: `请求失败!`, code: -3 }); | |
70 | 70 | } |
71 | 71 | xhr.onabort = function (info): void { |
72 | 72 | // cc.error("info3", info) |
73 | - resolve({ msg: `请求失败!`, code: -5 }); | |
73 | + resolve({ msg: `请求失败!`, code: -4 }); | |
74 | 74 | } |
75 | 75 | |
76 | 76 | xhr.open(method, url, true); |
77 | 77 | |
78 | 78 | if (method == "POST") { |
79 | 79 | xhr.setRequestHeader("Content-Type", "application/json;charset=utf-8")//application/x-www-form-urlencoded |
80 | + // if (cc.sys.os === 'Android') { | |
81 | + // cc.error("http__uid", AppSdkData.I.uid); | |
82 | + // xhr.setRequestHeader('Uuid', `${AppSdkData.I.uid}`); | |
83 | + // } else { | |
84 | + // xhr.setRequestHeader('Uuid', `909`); | |
85 | + // } | |
86 | + | |
80 | 87 | } |
81 | - xhr.timeout = 10000; | |
88 | + xhr.timeout = 3000; | |
89 | + // console.log(data) | |
82 | 90 | xhr.send(data); |
83 | 91 | }); |
84 | 92 | } | ... | ... |
wxsdk/platform/wx/WxStorage.ts.meta
1 | 1 | { |
2 | - "ver": "4.0.23", | |
3 | - "importer": "typescript", | |
4 | - "imported": true, | |
2 | + "ver": "1.0.8", | |
5 | 3 | "uuid": "6013014c-7aa3-4eb4-b818-583d937a9f05", |
6 | - "files": [], | |
7 | - "subMetas": {}, | |
8 | - "userData": {} | |
9 | -} | |
4 | + "isPlugin": false, | |
5 | + "loadPluginInWeb": true, | |
6 | + "loadPluginInNative": true, | |
7 | + "loadPluginInEditor": false, | |
8 | + "subMetas": {} | |
9 | +} | |
10 | 10 | \ No newline at end of file | ... | ... |
wxsdk/qq/QQPay.ts
... | ... | @@ -1,165 +0,0 @@ |
1 | -import { GAMEDATA } from '../base/SDKConst'; | |
2 | -import { EnvCode } from '../base/SDKEnum'; | |
3 | -import { SDKApi } from '../http/SDKApi'; | |
4 | -import DataService from '../service/DataService'; | |
5 | -import WxSystem from '../wx/WxSystem'; | |
6 | - | |
7 | -export default class QQPay { | |
8 | - /** | |
9 | - * 发起支付 | |
10 | - */ | |
11 | - pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}): Promise<any> { | |
12 | - return new Promise((resolve, reject) => { | |
13 | - let { Mode, OfferId, ZoneId, CurrencyType, Platform } = GAMEDATA.MidasPay; | |
14 | - // 环境配置,0:米大师正式环境 1:米大师沙箱环境 | |
15 | - let env = DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1; | |
16 | - // 平台类型,android or ios,config.js有配置走配置,否则判断系统id | |
17 | - let platform = DataService.I.Platform; | |
18 | - let pms = { | |
19 | - mode: Mode, | |
20 | - env, | |
21 | - platform, | |
22 | - offerId: OfferId, | |
23 | - currencyType: CurrencyType, | |
24 | - buyQuantity: params.money / 10, | |
25 | - zoneId: ZoneId | |
26 | - }; | |
27 | - let extend = ""; | |
28 | - for (let key in opts) { | |
29 | - extend += (`${key}=${opts[key]}&`) | |
30 | - } | |
31 | - extend = extend.substring(0, extend.length - 1); | |
32 | - extend = encodeURIComponent(extend); | |
33 | - | |
34 | - let payParams = { | |
35 | - ...this.buildParams(), | |
36 | - extend, | |
37 | - orderid: params.orderid, | |
38 | - // payid: params.payid, | |
39 | - goodid: params.goodid, | |
40 | - money: params.money, | |
41 | - platform | |
42 | - }; | |
43 | - console.log("payParams", payParams); | |
44 | - SDKApi.qqOrderReport(payParams).then(res => { | |
45 | - console.log("res", res); | |
46 | - if (!res.code) { | |
47 | - let { prepayId,starCurrency,setEnv } = res.data; | |
48 | - qq.requestMidasPayment({ | |
49 | - prepayId, | |
50 | - starCurrency, | |
51 | - setEnv, | |
52 | - success(res) { | |
53 | - // console.log("调用函数成功", res); | |
54 | - resolve({ code: 0, msg: '支付成功!' }) | |
55 | - }, | |
56 | - fail(err) { | |
57 | - // console.log("调用函数失败", res); | |
58 | - resolve({ code: err.errCode, msg: '支付失败' }); | |
59 | - }, | |
60 | - complete(res) { | |
61 | - console.log("调用完成", res); | |
62 | - }, | |
63 | - }) | |
64 | - } else { | |
65 | - reject(res); | |
66 | - } | |
67 | - }) | |
68 | - }); | |
69 | - } | |
70 | - | |
71 | - private async handlePaySuccess(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts: any, resolve: any, reject: any, t = 1000) { | |
72 | - let extend = ""; | |
73 | - for (let key in opts) { | |
74 | - extend += (`${key}=${opts[key]}&`) | |
75 | - } | |
76 | - extend = extend.substring(0, extend.length - 1); | |
77 | - extend = encodeURIComponent(extend); | |
78 | - let params = { | |
79 | - ...this.buildParams(), | |
80 | - extend, | |
81 | - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, | |
82 | - orderid: data.orderid, | |
83 | - payid: data.payid, goodid: data.goodid, | |
84 | - type: 1, | |
85 | - money: data.money, | |
86 | - platform: data.platform | |
87 | - }; | |
88 | - var that = this; | |
89 | - SDKApi.qqOrderReport(params) | |
90 | - .then(res => { | |
91 | - if (!res.code) { | |
92 | - resolve(res); | |
93 | - } else { | |
94 | - t = Math.min(t * 2, 60000) | |
95 | - // console.error("上报失败,重新上报", t) | |
96 | - setTimeout(() => { | |
97 | - that.handlePaySuccess(data, opts, resolve, reject, t) | |
98 | - }, t); | |
99 | - } | |
100 | - }) | |
101 | - } | |
102 | - | |
103 | - private handlePayError(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts, err: any, reject: any) { | |
104 | - console.log("支付失败", JSON.stringify(err)); | |
105 | - let type = 2; | |
106 | - if (err.errCode + '' == '1') { | |
107 | - type = 3; | |
108 | - } | |
109 | - let extend = ""; | |
110 | - for (let key in opts) { | |
111 | - extend += (`${key}=${opts[key]}&`) | |
112 | - } | |
113 | - extend = extend.substring(0, extend.length - 1); | |
114 | - extend = encodeURIComponent(extend); | |
115 | - let params = { | |
116 | - ...this.buildParams(), | |
117 | - extend, | |
118 | - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, | |
119 | - orderid: data.orderid, | |
120 | - payid: data.payid, goodid: data.goodid, | |
121 | - type, | |
122 | - money: data.money, | |
123 | - platform: data.platform | |
124 | - }; | |
125 | - SDKApi.qqOrderReport(params) | |
126 | - reject(err); | |
127 | - } | |
128 | - | |
129 | - /** | |
130 | - * 构建支付公用参数 | |
131 | - */ | |
132 | - private buildParams() { | |
133 | - let gameid = GAMEDATA.game_id; | |
134 | - let channel = DataService.I.ChannelId; | |
135 | - let openid = DataService.I.OpenId; | |
136 | - let brand = WxSystem.I.brand; | |
137 | - let model = WxSystem.I.model; | |
138 | - let version = WxSystem.I.version; | |
139 | - let system = WxSystem.I.system; | |
140 | - let sdkversion = WxSystem.I.SDKVersion; | |
141 | - let scene = DataService.I.Scene + ''; | |
142 | - let uid = DataService.I.UserId; | |
143 | - let token = DataService.I.Token; | |
144 | - let env = DataService.I.EnvEnum === 1 ? 'pre' : 'prod'; | |
145 | - return { | |
146 | - gameid, | |
147 | - openid, | |
148 | - channel, | |
149 | - brand, | |
150 | - model, | |
151 | - version, | |
152 | - system, | |
153 | - sdkversion, | |
154 | - scene, | |
155 | - uid, | |
156 | - token, | |
157 | - env | |
158 | - }; | |
159 | - } | |
160 | - | |
161 | - private static _instance: QQPay; | |
162 | - static get I(): QQPay { | |
163 | - return this._instance || (this._instance = new QQPay); | |
164 | - } | |
165 | -} | |
166 | 0 | \ No newline at end of file |
wxsdk/service/AdService.ts
... | ... | @@ -4,8 +4,9 @@ import WxCustom from "../wx/WxCustom"; |
4 | 4 | import WxInterstitial from "../wx/WxInterstitial"; |
5 | 5 | import { GAMEDATA } from "../base/SDKConst"; |
6 | 6 | import LogService from "./LogService"; |
7 | -import DouyinInterstitial from "../douyin/DouyinInterstitial"; | |
8 | -import { sys } from "cc"; | |
7 | +import AlipayInterstitial from "../alipay/AlipayInterstitial"; | |
8 | +import AlipayApi from "../alipay/AlipayApi"; | |
9 | +import AlipayBanner from "../alipay/AlipayBanner"; | |
9 | 10 | |
10 | 11 | |
11 | 12 | |
... | ... | @@ -17,37 +18,80 @@ export default class AdService { |
17 | 18 | * @param adUnitId |
18 | 19 | * @param opts |
19 | 20 | */ |
20 | - createBanner(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean,isCreate?:boolean }) { | |
21 | - return WxBanner.I.create(adUnitId, opts); | |
21 | + createBanner(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { | |
22 | + | |
23 | + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
24 | + return null | |
25 | + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
26 | + return AlipayBanner.I.create(adUnitId) | |
27 | + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
28 | + return WxBanner.I.create(adUnitId, opts); | |
29 | + } | |
22 | 30 | } |
23 | 31 | /** |
24 | 32 | * banner 显示 ps:创建默认显示 |
25 | 33 | */ |
26 | 34 | showBanner() { |
27 | - WxBanner.I.show() | |
35 | + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
36 | + | |
37 | + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
38 | + AlipayBanner.I.show(); | |
39 | + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
40 | + WxBanner.I.show(); | |
41 | + } | |
42 | + | |
28 | 43 | } |
29 | 44 | /** |
30 | 45 | * banner 隐藏 |
31 | 46 | */ |
32 | 47 | hideBanner() { |
33 | - WxBanner.I.hide(); | |
48 | + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
49 | + | |
50 | + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
51 | + AlipayBanner.I.hide(); | |
52 | + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
53 | + WxBanner.I.hide(); | |
54 | + } | |
34 | 55 | } |
35 | 56 | /** |
36 | 57 | * banner 销毁 |
37 | 58 | */ |
38 | 59 | destoryBanner() { |
39 | - WxBanner.I.destory(); | |
60 | + | |
61 | + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
62 | + | |
63 | + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
64 | + AlipayBanner.I.destory(); | |
65 | + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
66 | + WxBanner.I.destory(); | |
67 | + } | |
40 | 68 | } |
41 | 69 | |
42 | - | |
70 | + /** | |
71 | + * 初始化插屏 | |
72 | + * @param adUnitId | |
73 | + */ | |
74 | + initInterstitialAd(adUnitId?: string) { | |
75 | + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
76 | + // return DouyinInterstitial.initInterstitialAd(adUnitId); | |
77 | + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
78 | + AlipayInterstitial.initInterstitialAd(adUnitId) | |
79 | + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
80 | + return WxInterstitial.initInterstitialAd(adUnitId) | |
81 | + } | |
82 | + } | |
43 | 83 | /** |
44 | 84 | * 插屏 |
45 | 85 | * @param adUnitId |
46 | 86 | */ |
47 | 87 | createInterstitialAd(adUnitId: string) { |
48 | - if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME) { | |
49 | - return DouyinInterstitial.showInterstitialAd(adUnitId); | |
50 | - } else { | |
88 | + console.log('~~~~~~~~~~~插屏'); | |
89 | + // return WxInterstitial.showInterstitialAd(adUnitId) | |
90 | + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
91 | + // return DouyinInterstitial.initInterstitialAd(adUnitId); | |
92 | + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
93 | + AlipayInterstitial.showInterstitialAd(adUnitId) | |
94 | + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
51 | 95 | return WxInterstitial.showInterstitialAd(adUnitId) |
52 | 96 | } |
53 | 97 | } |
... | ... | @@ -86,7 +130,13 @@ export default class AdService { |
86 | 130 | let { id, appid, path, game } = data; |
87 | 131 | LogService.I.jumps(id, type); |
88 | 132 | if (!path) path = `?channel_id=${GAMEDATA.channel_id}`; |
89 | - return WxApi.I.navigateToMiniProgram(appid, path, opts) | |
133 | + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
134 | + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
135 | + return AlipayApi.I.navigateToMiniProgram(appid, path, opts) | |
136 | + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
137 | + return WxApi.I.navigateToMiniProgram(appid, path, opts) | |
138 | + } | |
139 | + | |
90 | 140 | } |
91 | 141 | |
92 | 142 | ... | ... |
wxsdk/service/DataService.ts
... | ... | @@ -16,25 +16,13 @@ export default class DataService { |
16 | 16 | this._data = new SdkData; |
17 | 17 | // 0点数据变动 |
18 | 18 | let expiration = +((this.nextDay() - Date.now()) / 1000).toFixed(0); |
19 | - setTimeout(this.resetData.bind(this), expiration * 1000); | |
20 | - if (typeof wx != 'undefined' || typeof my != 'undefined') { | |
21 | - wx.onShow(this.onShow.bind(this)); | |
22 | - wx.onHide(this.onHide.bind(this)); | |
23 | - } | |
24 | - } | |
19 | + setTimeout(this.resetData, expiration * 1000); | |
25 | 20 | |
26 | - onShow() { | |
27 | - // console.log("dataOnshow"); | |
28 | - this.updateTodayOnlineTime(); | |
29 | - } | |
30 | - onHide() { | |
31 | - // console.log("dataOnhide"); | |
32 | - clearInterval(this.timeInterval); | |
33 | 21 | } |
34 | 22 | |
35 | - private resetData() { | |
23 | + private resetData(){ | |
36 | 24 | this.setPtm(0);//更新当天是否300s |
37 | - this.setLogindays(this.logindays + 1);// 更新登录天数 | |
25 | + this.setLogindays(this.logindays+1);// 更新登录天数 | |
38 | 26 | this.setIsnew(0);//更新新老用户 |
39 | 27 | } |
40 | 28 | |
... | ... | @@ -49,6 +37,7 @@ export default class DataService { |
49 | 37 | }; |
50 | 38 | } |
51 | 39 | |
40 | + | |
52 | 41 | get Data(): SdkData { |
53 | 42 | return this._data; |
54 | 43 | } |
... | ... | @@ -527,13 +516,6 @@ export default class DataService { |
527 | 516 | return this; |
528 | 517 | } |
529 | 518 | |
530 | - // public addOnlineTime(t) { | |
531 | - // let expiration = +((this.nextDay() - Date.now()) / 1000).toFixed(0); | |
532 | - // let time = StorageUtils.I.get("pcsdk_today_online_time") || 0; | |
533 | - // time += t; | |
534 | - // StorageUtils.I.set("pcsdk_today_online_time", time, expiration) | |
535 | - // } | |
536 | - | |
537 | 519 | private timeInterval |
538 | 520 | public updateTodayOnlineTime() { |
539 | 521 | let dot = StorageUtils.I.get("pcsdk_today_online_time_300") || 0; |
... | ... | @@ -547,16 +529,14 @@ export default class DataService { |
547 | 529 | return; |
548 | 530 | } else { |
549 | 531 | this.setPtm(0) |
550 | - this.timeInterval = setInterval(this.stayFun.bind(this), 1000); | |
532 | + this.timeInterval = setInterval(this.stayFun.bind(this), 5000); | |
551 | 533 | } |
552 | 534 | } |
553 | - | |
554 | - | |
555 | 535 | private stayFun() { |
556 | 536 | let expiration = +((this.nextDay() - Date.now()) / 1000).toFixed(0); |
557 | 537 | let time = StorageUtils.I.get("pcsdk_today_online_time") || 0; |
558 | - time += 1; | |
559 | - StorageUtils.I.set("pcsdk_today_online_time", time, expiration); | |
538 | + time += 5; | |
539 | + StorageUtils.I.set("pcsdk_today_online_time", time, expiration) | |
560 | 540 | let dot = StorageUtils.I.get("pcsdk_today_online_time_300") || 0; |
561 | 541 | if (dot === 1) { |
562 | 542 | this.setPtm(1) |
... | ... | @@ -567,7 +547,7 @@ export default class DataService { |
567 | 547 | }, expiration * 1000); |
568 | 548 | return; |
569 | 549 | } |
570 | - // console.log("newUserTime", time, dot) | |
550 | + // console.log("newUserTime", newUserTime, newUserDot) | |
571 | 551 | if (time >= 300 && dot == 0) { |
572 | 552 | StorageUtils.I.set("pcsdk_today_online_time_300", 1, expiration); |
573 | 553 | this.setPtm(1) | ... | ... |
wxsdk/service/GameService.ts
1 | -import { sys } from "cc"; | |
2 | -import { GAMEDATA, SDKVersion, __LOG__ } from "../base/SDKConst"; | |
3 | -import DouyinPay from "../douyin/DouyinPay"; | |
1 | +import DataService from "./DataService"; | |
4 | 2 | import { SDKApi } from "../http/SDKApi"; |
5 | -import QQPay from "../qq/QQPay"; | |
6 | -import WxApi from "../wx/WxApi"; | |
3 | +import { GAMEDATA, SDKVersion, __LOG__ } from "../base/SDKConst"; | |
7 | 4 | import WxLogin from "../wx/WxLogin"; |
5 | +import WxApi from "../wx/WxApi"; | |
8 | 6 | import WxPay from "../wx/WxPay"; |
9 | 7 | import WxSystem from "../wx/WxSystem"; |
10 | -import DataService from "./DataService"; | |
11 | -import ZfbPay from "../alipay/zfbPay"; | |
12 | 8 | |
13 | 9 | |
14 | 10 | export default class GameService { |
... | ... | @@ -39,6 +35,7 @@ export default class GameService { |
39 | 35 | return WxLogin.I.login(isAuthorize); |
40 | 36 | } |
41 | 37 | |
38 | + | |
42 | 39 | saveData(key: string, content: string) { |
43 | 40 | return SDKApi.saveData({ key, content, uid: DataService.I.UserId, token: DataService.I.Token }); |
44 | 41 | } |
... | ... | @@ -65,12 +62,38 @@ export default class GameService { |
65 | 62 | adList(adtyp) { |
66 | 63 | return SDKApi.adList({ adtyp, uid: DataService.I.UserId, token: DataService.I.Token }) |
67 | 64 | } |
68 | - | |
69 | - wxencrypted(iv, encryptedData) { | |
70 | - return SDKApi.wxencrypted({ iv, encryptedData, openid: DataService.I.OpenId, token: DataService.I.Token, uid: DataService.I.UserId }) | |
65 | + getGameNotice() { | |
66 | + return SDKApi.notice(); | |
71 | 67 | } |
72 | 68 | |
73 | 69 | |
70 | + // subScribe(tmplIds: Array<string>, ids: Array<string>): Promise<any> { | |
71 | + // return new Promise((resolve, reject) => { | |
72 | + // WxApi.I.subscribeMessage(tmplIds) | |
73 | + // .then((ret: any) => { | |
74 | + // ret = ret || {}; | |
75 | + // let acceptKeys = tmplIds.filter((idKey: string) => ret[idKey] && ret[idKey] === 'accept'); | |
76 | + // if (!acceptKeys.length) { | |
77 | + // reject({ errCode: 0, errMsg: '点击取消订阅' }); | |
78 | + // } else { | |
79 | + // let uid = +DataService.I.UserId; | |
80 | + // let token = DataService.I.Token + ''; | |
81 | + // let openid = DataService.I.OpenId + ''; | |
82 | + // let id = ids//JSON.stringify() | |
83 | + // SDKApi.subscribe({ | |
84 | + // uid, | |
85 | + // token, | |
86 | + // openid, | |
87 | + // status: 1, | |
88 | + // id, | |
89 | + // }) | |
90 | + // resolve({ code: 0, msg: '订阅成功!' }) | |
91 | + // } | |
92 | + | |
93 | + // }) | |
94 | + // .catch(err => reject(err)); | |
95 | + // }); | |
96 | + // } | |
74 | 97 | subScribe(tmplIds: Array<string>, success: Function, fail: Function): Promise<any> { |
75 | 98 | return new Promise((resolve, reject) => { |
76 | 99 | WxApi.I.subscribeMessage(tmplIds) |
... | ... | @@ -79,15 +102,55 @@ export default class GameService { |
79 | 102 | let acceptKeys = tmplIds.filter((idKey: string) => ret[idKey] && ret[idKey] === 'accept'); |
80 | 103 | if (!acceptKeys.length) { |
81 | 104 | fail() |
82 | - resolve({ errCode: 0, errMsg: '点击取消订阅' }); | |
105 | + reject({ errCode: 0, errMsg: '点击取消订阅' }); | |
106 | + | |
83 | 107 | } else { |
108 | + // let uid = +DataService.I.UserId; | |
109 | + // let token = DataService.I.Token + ''; | |
110 | + // let openid = DataService.I.OpenId + ''; | |
111 | + // UserManager.I.issubscribe = true; | |
84 | 112 | success(acceptKeys) |
85 | 113 | console.log('订阅成功', ret, acceptKeys) |
114 | + // SDKApi.subscribe({ | |
115 | + // uid, | |
116 | + // token, | |
117 | + // openid, | |
118 | + // status: 1, | |
119 | + // message: encodeURI(message), | |
120 | + // sendtime: sendtime, | |
121 | + // time: time, | |
122 | + // }) | |
86 | 123 | resolve(ret); |
87 | 124 | } |
125 | + // GameService.I.subScribe(acceptKeys) | |
126 | + // .then(() => { | |
127 | + // resolve(ret); | |
128 | + // DebugUtils.I.dynamic('====> PCSDK subScribe订阅消息成功', ret); | |
129 | + // }) | |
130 | + // .catch((err) => reject(err || { errCode: 0, errMsg: 'GameApi subScribe请求错误' })); | |
131 | + | |
88 | 132 | }) |
89 | - .catch(err => resolve(err)); | |
133 | + .catch(err => reject(err)); | |
90 | 134 | }); |
135 | + // return WxApi.I.subscribeMessage(template_ids); | |
136 | + } | |
137 | + | |
138 | + async sendSubScribe(tmplIds: Array<string>, message: string, sendtime: number, time: number = 0) { | |
139 | + let uid = +DataService.I.UserId; | |
140 | + let token = DataService.I.Token + ''; | |
141 | + let openid = DataService.I.OpenId + ''; | |
142 | + | |
143 | + let back = await SDKApi.sendsubscribe({ | |
144 | + uid, | |
145 | + token, | |
146 | + openid, | |
147 | + status: 1, | |
148 | + message: encodeURIComponent(message), | |
149 | + sendtime: Math.floor(sendtime), | |
150 | + time: time, | |
151 | + temid: tmplIds[0] | |
152 | + }) | |
153 | + return back; | |
91 | 154 | } |
92 | 155 | |
93 | 156 | /** |
... | ... | @@ -97,18 +160,7 @@ export default class GameService { |
97 | 160 | * @returns |
98 | 161 | */ |
99 | 162 | pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}) { |
100 | - if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME) { | |
101 | - return DouyinPay.I.pay(params, opts); | |
102 | - } else { | |
103 | - if (typeof my != 'undefined') { | |
104 | - return ZfbPay.I.pay(params, opts); | |
105 | - } else if (typeof qq != 'undefined') { | |
106 | - console.log("QQ支付") | |
107 | - return QQPay.I.pay(params, opts); | |
108 | - } else { | |
109 | - return WxPay.I.pay(params, opts); | |
110 | - } | |
111 | - } | |
163 | + return WxPay.I.pay(params, opts); | |
112 | 164 | } |
113 | 165 | /** |
114 | 166 | * 订单查询 |
... | ... | @@ -136,38 +188,6 @@ export default class GameService { |
136 | 188 | return SDKApi.goodslist(); |
137 | 189 | } |
138 | 190 | |
139 | - | |
140 | - /** | |
141 | - * 文本检测 | |
142 | - */ | |
143 | - checkmsg(scene: number, content: string, nickname?: string, title?: string, signature?: string) { | |
144 | - let gameid = GAMEDATA.game_id; | |
145 | - let uid = DataService.I.UserId; | |
146 | - let token = DataService.I.Token; | |
147 | - let openid = DataService.I.OpenId; | |
148 | - return SDKApi.checkmsg({ | |
149 | - gameid, | |
150 | - uid, | |
151 | - token, | |
152 | - openid, | |
153 | - scene, content, nickname, title, signature | |
154 | - }) | |
155 | - } | |
156 | - /** | |
157 | - * 更换昵称和头像 | |
158 | - */ | |
159 | - updateNickname(nickname: string, headurl: string) { | |
160 | - let gameid = GAMEDATA.game_id; | |
161 | - let uid = DataService.I.UserId; | |
162 | - let token = DataService.I.Token; | |
163 | - let pkv = SDKVersion; | |
164 | - return SDKApi.updateNickname({ | |
165 | - gameid, uid, token, pkv, | |
166 | - nickname, headurl | |
167 | - }) | |
168 | - } | |
169 | - | |
170 | - | |
171 | 191 | /** |
172 | 192 | * 构建登录/弱登录公用参数 |
173 | 193 | */ |
... | ... | @@ -217,6 +237,58 @@ export default class GameService { |
217 | 237 | } |
218 | 238 | |
219 | 239 | |
240 | + //阿里增量任务 | |
241 | + async aliMission(action_code, success: Function, fail: Function) { | |
242 | + let res = await SDKApi.aliMission({ | |
243 | + ...this.buildParamsAli(action_code), | |
244 | + }); | |
245 | + if (res.code) { | |
246 | + fail(res); | |
247 | + } else | |
248 | + success(res); | |
249 | + } | |
250 | + | |
251 | + /** | |
252 | + * { | |
253 | + "uid": 99, | |
254 | + "token": "12313123werwerwerewrw", | |
255 | + "openid": "2088012968344861", | |
256 | + "action_code": "pplwg_game_pass_level_3", | |
257 | + "action_finish_channel": "gamecenter" | |
258 | + } | |
259 | + * 阿里增量任务 | |
260 | + */ | |
261 | + public buildParamsAli(_action_code) { | |
262 | + console.log('阿里增量任务') | |
263 | + if (window['my'] == undefined) return; | |
264 | + let channel = 'other'; | |
265 | + let info = my.getLaunchOptionsSync(); | |
266 | + // console.log('~~~~~~~~~~~~action_finish_channel=', info); | |
267 | + // console.log('~~~~~~~~~~~~action_finish_channel=', info.query); | |
268 | + // console.log('~~~~~~~~~~~~action_finish_channel=', info.query.channel); | |
269 | + if (info.query.channel == undefined) { | |
270 | + channel = 'other'; | |
271 | + } else { | |
272 | + if (info.query.channel.length <= 0 || info.query.channel == null) { | |
273 | + channel = 'other'; | |
274 | + } else { | |
275 | + channel = info.query.channel; | |
276 | + } | |
277 | + } | |
278 | + | |
279 | + let uid = DataService.I.UserId; | |
280 | + let token = DataService.I.Token; | |
281 | + let openid = DataService.I.OpenId; | |
282 | + let action_code = _action_code; | |
283 | + let action_finish_channel = channel | |
284 | + return { | |
285 | + uid, | |
286 | + token, | |
287 | + openid, | |
288 | + action_code, | |
289 | + action_finish_channel | |
290 | + }; | |
291 | + } | |
220 | 292 | |
221 | 293 | /** |
222 | 294 | * 构建登录/弱登录公用参数 | ... | ... |
wxsdk/service/LogService.ts
... | ... | @@ -199,7 +199,7 @@ export default class LogService { |
199 | 199 | * @param times 时间 |
200 | 200 | * @param perc 失败时的完成进度 (浮点数) |
201 | 201 | */ |
202 | - async levelEnd(stageid, stagename, pattern, event, times, perc?) { | |
202 | + async levelEnd(stageid, stagename, pattern, event, times, perc?, valence=0) { | |
203 | 203 | let fun = () => SDKApi.level({ |
204 | 204 | ...this.buildParams(), |
205 | 205 | stageid, |
... | ... | @@ -208,7 +208,8 @@ export default class LogService { |
208 | 208 | event, |
209 | 209 | times, |
210 | 210 | perc, |
211 | - typ: 3 | |
211 | + typ: 3, | |
212 | + valence | |
212 | 213 | }) |
213 | 214 | this.checkLogin(fun); |
214 | 215 | } |
... | ... | @@ -458,25 +459,25 @@ export default class LogService { |
458 | 459 | /** |
459 | 460 | * 客户端日志 |
460 | 461 | */ |
461 | - clientLog(content, level = SDKLogLevel.debug) { | |
462 | + clientLog(content, level = LogLevel.debug) { | |
462 | 463 | SDKApi.client_log({ |
463 | 464 | APIVersion: '0.6.0', |
464 | 465 | gameid: GAMEDATA.game_id, |
465 | 466 | cacheUserId: StorageUtils.I.get("userId") || "0", |
466 | - level: SDKLogLevel[level], | |
467 | + level: LogLevel[level], | |
467 | 468 | content |
468 | 469 | }) |
469 | 470 | switch (level) { |
470 | - case SDKLogLevel.error: | |
471 | + case LogLevel.error: | |
471 | 472 | console.error(content); |
472 | 473 | break; |
473 | - case SDKLogLevel.debug: | |
474 | + case LogLevel.debug: | |
474 | 475 | console.log(content); |
475 | 476 | break; |
476 | - case SDKLogLevel.info: | |
477 | + case LogLevel.info: | |
477 | 478 | console.info(content); |
478 | 479 | break; |
479 | - case SDKLogLevel.warning: | |
480 | + case LogLevel.warning: | |
480 | 481 | console.warn(content); |
481 | 482 | break; |
482 | 483 | default: |
... | ... | @@ -510,22 +511,6 @@ export default class LogService { |
510 | 511 | }) |
511 | 512 | this.checkLogin(fun); |
512 | 513 | } |
513 | - /** | |
514 | - * loading上报 | |
515 | - * @param typ 1开始加载、2加载进行中、3加载结束 | |
516 | - * @param stageid 加载id | |
517 | - * @param stagename 加载内容 | |
518 | - * @param event complete:成功 fail:失败 | |
519 | - * @param times 加载消耗时间 单位毫秒 | |
520 | - * @param perc 完成度 | |
521 | - */ | |
522 | - loading(typ: string, stageid: string, stagename: string, event: string, times: string, perc?: number) { | |
523 | - let fun = () => SDKApi.loading({ | |
524 | - ...this.buildParams(), | |
525 | - typ, stageid, stagename, event, times, perc | |
526 | - }) | |
527 | - this.checkLogin(fun); | |
528 | - } | |
529 | 514 | |
530 | 515 | |
531 | 516 | /** |
... | ... | @@ -586,7 +571,7 @@ export default class LogService { |
586 | 571 | error:更严重的问题,软件没能执行一些功能 |
587 | 572 | critical:一个严重的错误,这表明程序本身可能无法继续运行 |
588 | 573 | */ |
589 | -export enum SDKLogLevel { | |
574 | +export enum LogLevel { | |
590 | 575 | debug, |
591 | 576 | info, |
592 | 577 | warning, | ... | ... |
wxsdk/service/ShareVideoService.ts
... | ... | @@ -6,7 +6,6 @@ import { __LOG__, GAMEDATA } from "../base/SDKConst"; |
6 | 6 | import { SDKApi } from "../http/SDKApi"; |
7 | 7 | import DataService from "./DataService"; |
8 | 8 | import SDKVideo from "../share/SDKVideo"; |
9 | -import { sys } from "cc"; | |
10 | 9 | |
11 | 10 | export default class ShareVideoService { |
12 | 11 | private forwardKey?: string; |
... | ... | @@ -28,28 +27,18 @@ export default class ShareVideoService { |
28 | 27 | this.forward(this.forwardKey); |
29 | 28 | } |
30 | 29 | |
31 | - private cnt: number = 1 | |
32 | - async initList() { //初始化List | |
30 | + async init() { | |
33 | 31 | let data = await SDKApi.ShareList(); |
34 | - if (data.code) { | |
35 | - console.log('拉取ShareList失败!') | |
36 | - setTimeout(this.initList.bind(this), 200 * this.cnt) | |
37 | - this.cnt++; | |
38 | - return | |
39 | - } | |
40 | - console.log('拉取ShareList成功!') | |
41 | - console.log('拉取ShareList成功!',JSON.stringify(data)); | |
42 | 32 | this.setShareVideoData(data); |
43 | - if (this.forwardKey) this.forward(this.forwardKey); | |
44 | - } | |
45 | - async init() { | |
46 | - this.initList(); | |
33 | + // console.log(JSON.stringify(data)) | |
47 | 34 | SDKShare.I.updateShareMenu(true);//打开群分享 |
48 | - if (sys.platform === sys.Platform.WECHAT_GAME) { | |
49 | - if (GAMEDATA.shareMessageToFriend.scene > 0) { | |
50 | - wx.setMessageToFriendQuery({ shareMessageToFriendScene: GAMEDATA.shareMessageToFriend.scene }) | |
51 | - } | |
35 | + | |
36 | + | |
37 | + if (GAMEDATA.shareMessageToFriend.scene > 0) { | |
38 | + my.setMessageToFriendQuery({ shareMessageToFriendScene: GAMEDATA.shareMessageToFriend.scene }) | |
52 | 39 | } |
40 | + | |
41 | + if (this.forwardKey) this.forward(this.forwardKey); | |
53 | 42 | } |
54 | 43 | |
55 | 44 | preload = true; |
... | ... | @@ -411,10 +400,6 @@ export default class ShareVideoService { |
411 | 400 | return list[index]; |
412 | 401 | } |
413 | 402 | |
414 | - onShareTimeline(title?: string, imageUrl?: string, imagePreviewUrl?: string, query?: string) { | |
415 | - return SDKShare.I.onShareTimeline(title, imageUrl, imagePreviewUrl, query); | |
416 | - } | |
417 | - | |
418 | 403 | private createQuery(params = {}): string { |
419 | 404 | let q = params["query"]; |
420 | 405 | delete params["query"]; | ... | ... |
wxsdk/service/entity/SdkData.ts.meta
1 | 1 | { |
2 | - "ver": "4.0.23", | |
3 | - "importer": "typescript", | |
4 | - "imported": true, | |
2 | + "ver": "1.0.8", | |
5 | 3 | "uuid": "f09e38ff-4d68-417e-8904-949127e4d321", |
6 | - "files": [], | |
7 | - "subMetas": {}, | |
8 | - "userData": {} | |
9 | -} | |
4 | + "isPlugin": false, | |
5 | + "loadPluginInWeb": true, | |
6 | + "loadPluginInNative": true, | |
7 | + "loadPluginInEditor": false, | |
8 | + "subMetas": {} | |
9 | +} | |
10 | 10 | \ No newline at end of file | ... | ... |
wxsdk/service/entity/ShareData.ts.meta
1 | 1 | { |
2 | - "ver": "4.0.23", | |
3 | - "importer": "typescript", | |
4 | - "imported": true, | |
2 | + "ver": "1.0.8", | |
5 | 3 | "uuid": "d9db9b13-470b-456d-95ff-75354ec23ca0", |
6 | - "files": [], | |
7 | - "subMetas": {}, | |
8 | - "userData": {} | |
9 | -} | |
4 | + "isPlugin": false, | |
5 | + "loadPluginInWeb": true, | |
6 | + "loadPluginInNative": true, | |
7 | + "loadPluginInEditor": false, | |
8 | + "subMetas": {} | |
9 | +} | |
10 | 10 | \ No newline at end of file | ... | ... |
wxsdk/share/SDKShare.ts
... | ... | @@ -48,18 +48,20 @@ export default class SDKShare { |
48 | 48 | reject(null); |
49 | 49 | } |
50 | 50 | }; |
51 | + // 是否模拟分享 | |
52 | + this.shareSimulate && !opts.closeSimulate && this.simulate({ ...callbackObj }); | |
51 | 53 | |
52 | 54 | if (this.shareSimulate && opts.closeSimulate) { |
53 | 55 | LogService.I.share(shareKey, share_id, DOT_SHARE_TYPE.share) |
54 | 56 | } |
55 | 57 | // 主动拉起转发 |
56 | - if (typeof my != 'undefined') { | |
58 | + if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
57 | 59 | //模拟分享支付宝上面会失败 |
58 | 60 | return AlipayApi.I.shareAppMessage(commonObj, callbackObj) |
61 | + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
62 | + return wx.shareAppMessage(commonObj); | |
59 | 63 | } else { |
60 | - // 是否模拟分享 | |
61 | - this.shareSimulate && !opts.closeSimulate && this.simulate({ ...callbackObj }); | |
62 | - wx.shareAppMessage(commonObj); | |
64 | + return callbackObj.success(); | |
63 | 65 | } |
64 | 66 | }); |
65 | 67 | } |
... | ... | @@ -69,7 +71,7 @@ export default class SDKShare { |
69 | 71 | */ |
70 | 72 | updateShareMenu(value) { |
71 | 73 | if (typeof wx == 'undefined') return |
72 | - wx.updateShareMenu({ | |
74 | + my.updateShareMenu({ | |
73 | 75 | withShareTicket: value |
74 | 76 | }); |
75 | 77 | } |
... | ... | @@ -81,12 +83,10 @@ export default class SDKShare { |
81 | 83 | forward(params: any, opts: any = {}) { |
82 | 84 | let me = this; |
83 | 85 | let { title, imageUrl, query, imageUrlId } = params; |
84 | - if (typeof my != 'undefined') { | |
86 | + if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
85 | 87 | my.onShareAppMessage = function () { |
86 | 88 | return { |
87 | 89 | title: title, |
88 | - scImgUrl: imageUrl, | |
89 | - bgImgUrl: 'https://wxsdk-cdn.miso-lab.com/moon-island/share/zfbshare.jpeg', | |
90 | 90 | success: (ret?: any) => { |
91 | 91 | __LOG__ && console.error('WxShare forward success'); |
92 | 92 | opts.success && opts.success.call(opts.context, ret); |
... | ... | @@ -100,36 +100,33 @@ export default class SDKShare { |
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
103 | - return; | |
103 | + } else { | |
104 | + wx.onShareAppMessage(function () { | |
105 | + let obj = { | |
106 | + title, | |
107 | + imageUrl, | |
108 | + query, | |
109 | + imageUrlId: imageUrlId || '', | |
110 | + success: (ret?: any) => { | |
111 | + __LOG__ && console.error('WxShare forward success'); | |
112 | + opts.success && opts.success.call(opts.context, ret); | |
113 | + }, | |
114 | + fail: (err?: any) => { | |
115 | + __LOG__ && console.error('WxShare forward fail'); | |
116 | + opts.fail && opts.fail.call(opts.context, err); | |
117 | + }, | |
118 | + cancel: () => { | |
119 | + __LOG__ && console.error('WxShare forward cancel', null); | |
120 | + opts.fail && opts.fail.call(opts.context, null); | |
121 | + } | |
122 | + }; | |
123 | + // 模拟分享 | |
124 | + me.shareSimulate && !opts.closeSimulate && me.simulate({ ...obj }); | |
125 | + return obj; | |
126 | + }); | |
127 | + // 显示当前页面的转发按钮 | |
128 | + wx.showShareMenu({}); | |
104 | 129 | } |
105 | - wx.onShareAppMessage(function () { | |
106 | - let obj = { | |
107 | - title, | |
108 | - imageUrl, | |
109 | - query, | |
110 | - imageUrlId: imageUrlId || '', | |
111 | - success: (ret?: any) => { | |
112 | - __LOG__ && console.error('WxShare forward success'); | |
113 | - opts.success && opts.success.call(opts.context, ret); | |
114 | - }, | |
115 | - fail: (err?: any) => { | |
116 | - __LOG__ && console.error('WxShare forward fail'); | |
117 | - opts.fail && opts.fail.call(opts.context, err); | |
118 | - }, | |
119 | - cancel: () => { | |
120 | - __LOG__ && console.error('WxShare forward cancel', null); | |
121 | - opts.fail && opts.fail.call(opts.context, null); | |
122 | - } | |
123 | - }; | |
124 | - // 模拟分享 | |
125 | - me.shareSimulate && !opts.closeSimulate && me.simulate({ ...obj }); | |
126 | - return obj; | |
127 | - }); | |
128 | - // 显示当前页面的转发按钮 "shareAppMessage"表示“发送给朋友”按钮,"shareTimeline"表示“分享到朋友圈”按钮 | |
129 | - wx.showShareMenu({ | |
130 | - withShareTicket: true, | |
131 | - menus: ['shareAppMessage', 'shareTimeline'] | |
132 | - }) | |
133 | 130 | |
134 | 131 | } |
135 | 132 | |
... | ... | @@ -151,18 +148,4 @@ export default class SDKShare { |
151 | 148 | SimulateShare.I.bind(data); |
152 | 149 | } |
153 | 150 | |
154 | - onShareTimeline(title?: string, imageUrl?: string, imagePreviewUrl?: string, query?: string) { | |
155 | - if (wx?.onShareTimeline) { | |
156 | - wx.onShareTimeline(() => { | |
157 | - return { | |
158 | - title,//朋友圈标题 | |
159 | - imageUrl, // 朋友圈 小图 | |
160 | - imagePreviewUrl,//朋友圈 预览大图 | |
161 | - query, | |
162 | - } | |
163 | - }) | |
164 | - } | |
165 | - | |
166 | - } | |
167 | - | |
168 | 151 | } |
169 | 152 | \ No newline at end of file | ... | ... |
wxsdk/share/SDKVideo.ts
1 | -import { sys } from "cc"; | |
2 | 1 | import { ShareVideoError, __LOG__ } from "../base/SDKConst"; |
3 | 2 | import { DOT_AD_TYPE, DOT_AD_STATUS } from "../base/SDKEnum"; |
4 | 3 | import LogService from "../service/LogService"; |
5 | -import TAMgr from "../../ta/TAMgr"; | |
6 | 4 | import AlipayApi from "../alipay/AlipayApi"; |
7 | 5 | |
8 | 6 | /* |
... | ... | @@ -36,6 +34,7 @@ export default class SDKVideo { |
36 | 34 | private isPreload: boolean = false |
37 | 35 | preloadVideo(adUnitId: string) { |
38 | 36 | if (this.preloadVideoAd || this.isPreload) return |
37 | + // console.log('preloadVideo--') | |
39 | 38 | this.isPreload = true; |
40 | 39 | let ad; |
41 | 40 | if (typeof my != 'undefined') { |
... | ... | @@ -96,12 +95,9 @@ export default class SDKVideo { |
96 | 95 | return reject({ ...ShareVideoError.VideoInvalid }); |
97 | 96 | |
98 | 97 | LogService.I.adStat(videoKey, this.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.request); |
99 | - TAMgr.Ins.dot('video', { | |
100 | - ad_key: videoKey, | |
101 | - type: DOT_AD_STATUS.request | |
102 | - }) | |
103 | - let videoAd | |
104 | - let hasVideo | |
98 | + let videoAd; | |
99 | + let hasVideo; | |
100 | + | |
105 | 101 | if (this.preloadVideoAd) { |
106 | 102 | __LOG__ && console.log("使用预加载视频") |
107 | 103 | hasVideo = true |
... | ... | @@ -167,7 +163,7 @@ export default class SDKVideo { |
167 | 163 | } |
168 | 164 | |
169 | 165 | } |
170 | - this.preloadVideo(adUnitId); | |
166 | + // this.preloadVideo(adUnitId); | |
171 | 167 | __LOG__ && console.warn('====> PCSDK WxVideo 请求视频adUnitId', adUnitId); |
172 | 168 | }); |
173 | 169 | } |
... | ... | @@ -183,11 +179,7 @@ export default class SDKVideo { |
183 | 179 | try { |
184 | 180 | __LOG__ && console.warn("handleLoaded2"); |
185 | 181 | LogService.I.adStat(this.videoKey, this.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.show) |
186 | - TAMgr.Ins.dot('video', { | |
187 | - ad_key: this.videoKey, | |
188 | - type: DOT_AD_STATUS.show | |
189 | - }) | |
190 | - if (sys.platform === sys.Platform.WECHAT_GAME && typeof qq == 'undefined') { | |
182 | + if (cc.sys.platform === cc.sys.WECHAT_GAME && typeof qq == 'undefined') { | |
191 | 183 | if (that.videoAd.isReady()) {//抖音、qq 没有 isReady |
192 | 184 | that.show_time = Date.now(); |
193 | 185 | await that.videoAd.show(); |
... | ... | @@ -218,18 +210,10 @@ export default class SDKVideo { |
218 | 210 | if (res && res.isEnded || res === undefined) { |
219 | 211 | // 统计看视频成功 |
220 | 212 | LogService.I.adStat(that.videoKey, that.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.complete) |
221 | - TAMgr.Ins.dot('video', { | |
222 | - ad_key: that.videoKey, | |
223 | - type: DOT_AD_STATUS.complete | |
224 | - }) | |
225 | 213 | that.resolve && that.resolve({ type: 2 }); |
226 | 214 | } else { |
227 | 215 | // console.log("视频关闭时间:", t) |
228 | 216 | LogService.I.adStat(that.videoKey, that.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.interrupt, t) |
229 | - TAMgr.Ins.dot('video', { | |
230 | - ad_key: that.videoKey, | |
231 | - type: DOT_AD_STATUS.interrupt | |
232 | - }) | |
233 | 217 | that.reject && that.reject({ ...ShareVideoError.VideoQuit }); |
234 | 218 | } |
235 | 219 | if (typeof my != 'undefined') { |
... | ... | @@ -237,7 +221,7 @@ export default class SDKVideo { |
237 | 221 | } else { |
238 | 222 | that.videoAd.offClose(that.handleClose); |
239 | 223 | } |
240 | - | |
224 | + that.preloadVideo(that.adUnitId); | |
241 | 225 | that._isPlaying = false; |
242 | 226 | that._isErrored = false; |
243 | 227 | } |
... | ... | @@ -246,11 +230,15 @@ export default class SDKVideo { |
246 | 230 | __LOG__ && console.warn('====> PCSDK WxVideo 加载视频广告失败', err); |
247 | 231 | let that = SDKVideo.I; |
248 | 232 | LogService.I.adStat(that.videoKey, that.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.fail) |
249 | - TAMgr.Ins.dot('video', { | |
250 | - ad_key: that.videoKey, | |
251 | - type: DOT_AD_STATUS.fail | |
252 | - }) | |
253 | - that.reject && that.reject({ ...ShareVideoError.VideoFail }); | |
233 | + // that.reject && that.reject({ ...ShareVideoError.VideoFail }); | |
234 | + if (that.reject) { | |
235 | + if (that.videoAd) | |
236 | + that.reject({ ...ShareVideoError.VideoFail }) | |
237 | + else { | |
238 | + let fail = { code: 1010, msg: '查看次数过多,请稍后再看!' } | |
239 | + that.reject({ ...fail }) | |
240 | + } | |
241 | + } | |
254 | 242 | if (typeof my != 'undefined') { |
255 | 243 | |
256 | 244 | } else { | ... | ... |
wxsdk/utils/RandomUtils.ts
... | ... | @@ -20,7 +20,7 @@ export default class RandomUtils { |
20 | 20 | static rand(min: number, max: number) { |
21 | 21 | min = min || 0; |
22 | 22 | max = max || 10000; |
23 | - return Math.floor(Math.random() * 10000) % (max - min) + min; | |
23 | + return Math.floor(Math.random() * 10000) % (max - min) + min; | |
24 | 24 | } |
25 | 25 | |
26 | 26 | static rang(min: number, max: number) { |
... | ... | @@ -30,5 +30,4 @@ export default class RandomUtils { |
30 | 30 | static randFloat(min: number, max: number) { |
31 | 31 | return parseFloat((Math.random() * (max - min) + min).toFixed(2)); |
32 | 32 | } |
33 | - | |
34 | 33 | } | ... | ... |
wxsdk/utils/SDKUtils.ts
wxsdk/utils/SignUtils.ts
... | ... | @@ -11,7 +11,7 @@ export default class SignUtils { |
11 | 11 | |
12 | 12 | createSign(params: any) { |
13 | 13 | let signStr = this.createQuery(params) + '' + GAMEDATA.appkey; |
14 | - // console.error("signStr",signStr) | |
14 | + // console.error("signStr:::"+ signStr) | |
15 | 15 | return Md5.hashStr(signStr); |
16 | 16 | } |
17 | 17 | |
... | ... | @@ -71,7 +71,7 @@ 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]] == undefined ||params[keys[i]] === 'undefined' || 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' || keys[i] === 'ver' || keys[i] === 'pkv') continue | |
75 | 75 | key = keys[i]; |
76 | 76 | i && (query += ''); |
77 | 77 | if (SDKUtils.isArray(params[key])) { | ... | ... |
wxsdk/utils/StorageUtils.ts
... | ... | @@ -9,11 +9,7 @@ export default class StorageUtils { |
9 | 9 | private store: any = null |
10 | 10 | |
11 | 11 | constructor() { |
12 | - if (typeof localStorage === 'object') | |
13 | - this.store = new Storage; | |
14 | - | |
15 | - if (typeof (wx) != "undefined") | |
16 | - this.store = new WxStorage; | |
12 | + this.store = cc.sys.localStorage; | |
17 | 13 | } |
18 | 14 | |
19 | 15 | private __isExpired(entity: any) { | ... | ... |
wxsdk/wx/Version.ts
... | ... | @@ -2,20 +2,23 @@ import { __LOG__ } from "../base/SDKConst"; |
2 | 2 | |
3 | 3 | enum PlatformType { |
4 | 4 | WX = 'wx', |
5 | - QQ = 'qq' | |
5 | + QQ = 'qq', | |
6 | + MY = 'my' | |
6 | 7 | } |
7 | 8 | enum Platform{ |
8 | - PlatformType = 'wx' | |
9 | + PlatformType = 'my' | |
9 | 10 | } |
10 | 11 | export default class Version { |
11 | 12 | private DEFUALT = '0.0.0'; |
12 | 13 | private VERSION = { |
13 | 14 | createRewardedVideoAd: { |
14 | 15 | [PlatformType.WX]: '2.0.4', |
15 | - [PlatformType.QQ]: '0.1.26' | |
16 | + [PlatformType.QQ]: '0.1.26', | |
17 | + [PlatformType.MY]: '10.3.70' | |
16 | 18 | }, |
17 | 19 | createInterstitialAd: { |
18 | - [PlatformType.WX]: '2.6.0' | |
20 | + [PlatformType.WX]: '2.6.0', | |
21 | + [PlatformType.MY]: '10.3.66' | |
19 | 22 | }, |
20 | 23 | createFeedbackButton: { |
21 | 24 | [PlatformType.WX]: '2.1.2' |
... | ... | @@ -25,7 +28,8 @@ export default class Version { |
25 | 28 | }, |
26 | 29 | createBannerAd: { |
27 | 30 | [PlatformType.WX]: '2.0.4', |
28 | - [PlatformType.QQ]: '0.1.26' | |
31 | + [PlatformType.QQ]: '0.1.26', | |
32 | + [PlatformType.MY]: '10.3.66' | |
29 | 33 | }, |
30 | 34 | createGameBanner: { |
31 | 35 | [PlatformType.WX]: '2.7.5' | ... | ... |
wxsdk/wx/WxApi.ts
... | ... | @@ -62,7 +62,7 @@ export default class WxApi { |
62 | 62 | if (!this.canIUse(Version.I.getVBannerAd())) return null; |
63 | 63 | |
64 | 64 | adIntervals = adIntervals || 30; |
65 | - return wx.createBannerAd({ | |
65 | + return my.createBannerAd({ | |
66 | 66 | adUnitId, |
67 | 67 | style |
68 | 68 | }); |
... | ... | @@ -84,8 +84,9 @@ export default class WxApi { |
84 | 84 | * 创建插屏广告组件 |
85 | 85 | */ |
86 | 86 | createInterstitialAd(adUnitId: string) { |
87 | - if (!this.canIUse(Version.I.getVInterstitialAd())) return null; | |
88 | - return wx.createInterstitialAd({ | |
87 | + // if (!this.canIUse(Version.I.getVInterstitialAd())) return null; | |
88 | + if (typeof my === 'undefined') return null | |
89 | + return my.createInterstitialAd({ | |
89 | 90 | adUnitId |
90 | 91 | }); |
91 | 92 | } |
... | ... | @@ -116,7 +117,7 @@ export default class WxApi { |
116 | 117 | createRewardedVideoAd(adUnitId: string) { |
117 | 118 | if (!this.canIUse(Version.I.getVRewardedVideoAd())) return null; |
118 | 119 | |
119 | - return wx.createRewardedVideoAd({ | |
120 | + return my.createRewardedAd({ | |
120 | 121 | adUnitId |
121 | 122 | }); |
122 | 123 | } |
... | ... | @@ -163,10 +164,10 @@ export default class WxApi { |
163 | 164 | } |
164 | 165 | |
165 | 166 | vibrateShort() { |
166 | - if (!this.canIUse(Version.I.getVVibrate())) return Promise.reject(null); | |
167 | + // if (!this.canIUse(Version.I.getVVibrate())) return Promise.reject(null); | |
167 | 168 | |
168 | 169 | return new Promise((resolve, reject) => { |
169 | - wx.vibrateShort({ | |
170 | + my.vibrateShort({ | |
170 | 171 | success: () => { |
171 | 172 | resolve(1); |
172 | 173 | }, |
... | ... | @@ -299,16 +300,25 @@ export default class WxApi { |
299 | 300 | */ |
300 | 301 | login(): Promise<any> { |
301 | 302 | return new Promise((resolve, reject) => { |
302 | - wx.login({ | |
303 | - success: (ret: any) => { | |
304 | - resolve(ret.code); | |
303 | + // wx.login({ | |
304 | + // success: (ret: any) => { | |
305 | + // resolve(ret.code); | |
306 | + // }, | |
307 | + // fail: (err: any) => { | |
308 | + // reject(err); | |
309 | + // WxApi.I.setAuthorize({ | |
310 | + // errorTip: 'wx.login fail', | |
311 | + // ...err | |
312 | + // }); | |
313 | + // } | |
314 | + // }); | |
315 | + my.getAuthCode({ | |
316 | + scopes: 'auth_base', | |
317 | + success: (res) => { | |
318 | + resolve(res.authCode); | |
305 | 319 | }, |
306 | 320 | fail: (err: any) => { |
307 | 321 | reject(err); |
308 | - WxApi.I.setAuthorize({ | |
309 | - errorTip: 'wx.login fail', | |
310 | - ...err | |
311 | - }); | |
312 | 322 | } |
313 | 323 | }); |
314 | 324 | }); |
... | ... | @@ -371,8 +381,8 @@ export default class WxApi { |
371 | 381 | /** |
372 | 382 | * 米大师充值 |
373 | 383 | */ |
374 | - requestMidasPayment(params: { mode: string; env: number; offerId: string; currencyType: string; platform: string; buyQuantity: number; zoneId: string,outTradeNo:string }): Promise<any> { | |
375 | - let { mode, env, offerId, currencyType, platform, buyQuantity, zoneId,outTradeNo } = params; | |
384 | + requestMidasPayment(params: { mode: string; env: number; offerId: string; currencyType: string; platform: string; buyQuantity: number; zoneId: string }): Promise<any> { | |
385 | + let { mode, env, offerId, currencyType, platform, buyQuantity, zoneId } = params; | |
376 | 386 | console.warn('====> PCSDK WxApi requestMidasPayment 支付参数', { |
377 | 387 | mode, |
378 | 388 | env, |
... | ... | @@ -380,8 +390,7 @@ export default class WxApi { |
380 | 390 | currencyType, |
381 | 391 | platform, |
382 | 392 | buyQuantity, |
383 | - zoneId, | |
384 | - outTradeNo | |
393 | + zoneId | |
385 | 394 | }); |
386 | 395 | return new Promise((resolve, reject) => { |
387 | 396 | wx.requestMidasPayment({ |
... | ... | @@ -392,7 +401,6 @@ export default class WxApi { |
392 | 401 | platform, |
393 | 402 | buyQuantity, |
394 | 403 | zoneId, |
395 | - outTradeNo, | |
396 | 404 | success: ret => { |
397 | 405 | if (ret && ret.errMsg === 'requestMidasPayment:ok') |
398 | 406 | resolve(ret); | ... | ... |
wxsdk/wx/WxBanner.ts
... | ... | @@ -42,7 +42,15 @@ export default class WxBanner { |
42 | 42 | private queue: Function[] = []; |
43 | 43 | private isEnd: boolean = false; |
44 | 44 | |
45 | - create(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean ,isCreate?:boolean}) { | |
45 | + create(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { | |
46 | + // console.log('wxbanner can not') | |
47 | + // console.log(my.env.clientVersion()) | |
48 | + if (SDKUtils.compareVersion(my.env.clientVersion, '10.3.66') < 0) return null; | |
49 | + // let a = my.env.clientVersion() | |
50 | + // console.log(a) | |
51 | + // if (!WxApi.I.canIUse(Version.I.getVBannerAd())) | |
52 | + // console.log('wxbanner can') | |
53 | + | |
46 | 54 | this.bannerParams = opts || {}; |
47 | 55 | if (opts && opts.bannerWidth) { |
48 | 56 | this.bannerWidth = opts.bannerWidth; |
... | ... | @@ -67,24 +75,19 @@ export default class WxBanner { |
67 | 75 | let style = { top: 0, left: (WxSystem.I.winWidth - this.bannerWidth) / 2, width: this.bannerWidth }; |
68 | 76 | style = { |
69 | 77 | ...style, |
70 | - top: 0 + this.bannerParams.offsetY, | |
78 | + top: WxSystem.I.winHeight - 100, | |
71 | 79 | }; |
72 | 80 | // 创建并判断是否存在 |
73 | 81 | // if (this.bannerParams.type === 2) |
74 | 82 | // this.bannerAd = wx.createGameBanner({ adUnitId, style: { left: style.left, top: this.bannerHeight } }); |
75 | 83 | // else |
76 | 84 | if (this.bannerAd) { |
77 | - if(opts && opts.isCreate){ | |
78 | - //重新创建 | |
79 | - console.log("重新创建banner") | |
80 | - }else{ | |
81 | - if (!opts || (opts && !opts.isOff)) { | |
82 | - this.show(false); | |
83 | - } | |
84 | - return | |
85 | + if (!opts || (opts && !opts.isOff)) { | |
86 | + this.show(false); | |
85 | 87 | } |
88 | + return | |
86 | 89 | } |
87 | - this.bannerAd = wx.createBannerAd({ adUnitId, style, adIntervals: this.bannerParams.adIntervals }); | |
90 | + this.bannerAd = my.createBannerAd({ adUnitId, style, adIntervals: this.bannerParams.adIntervals }); | |
88 | 91 | LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.request) |
89 | 92 | if (!this.bannerAd) { |
90 | 93 | WxBanner.I.handleQueue(); |
... | ... | @@ -204,6 +207,7 @@ export default class WxBanner { |
204 | 207 | let that = WxBanner.I; |
205 | 208 | that.unbind(); |
206 | 209 | that._isErrored = true; |
210 | + that.bannerAd?.destroy(); | |
207 | 211 | that.bannerAd = null; |
208 | 212 | that.handleQueue() |
209 | 213 | LogService.I.adStat('banner', that.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.fail) |
... | ... | @@ -213,9 +217,9 @@ export default class WxBanner { |
213 | 217 | |
214 | 218 | private unbind() { |
215 | 219 | if (this.bannerAd) { |
216 | - this.bannerAd.offLoad(this.onLoad); | |
217 | - this.bannerAd.offError(this.onError); | |
218 | - this.bannerAd.offResize(this.onResize); | |
220 | + // this.bannerAd.offLoad(this.onLoad); | |
221 | + // this.bannerAd.offError(this.onError); | |
222 | + // this.bannerAd.offResize(this.onResize); | |
219 | 223 | } |
220 | 224 | } |
221 | 225 | ... | ... |
wxsdk/wx/WxCustom.ts
... | ... | @@ -178,9 +178,9 @@ export default class WxCustom { |
178 | 178 | |
179 | 179 | private unbind() { |
180 | 180 | if (this.customAd) { |
181 | - this.customAd.offLoad(this.onLoad); | |
182 | - this.customAd.offClose(this.onClose); | |
183 | - this.customAd.offError(this.onError); | |
181 | + // this.customAd.offLoad(this.onLoad); | |
182 | + // this.customAd.offClose(this.onClose); | |
183 | + // this.customAd.offError(this.onError); | |
184 | 184 | } |
185 | 185 | } |
186 | 186 | ... | ... |
wxsdk/wx/WxInit.ts
... | ... | @@ -15,15 +15,15 @@ export default class WxInit { |
15 | 15 | |
16 | 16 | private constructor() { |
17 | 17 | this.onlineTime = DateUtils.nowTime; |
18 | - wx.onShow(this.onShow.bind(this)); | |
19 | - wx.onHide(this.onHide.bind(this)); | |
20 | - wx.onNetworkStatusChange(this.onNetworkStatusChange.bind(this)); | |
18 | + my.onShow(this.onShow.bind(this)); | |
19 | + my.onHide(this.onHide.bind(this)); | |
20 | + my.onNetworkStatusChange(this.onNetworkStatusChange.bind(this)); | |
21 | 21 | } |
22 | 22 | |
23 | 23 | init() { |
24 | 24 | let { platform } = WxSystem.I.SystemData; |
25 | 25 | let launchData = WxLaunch.I.LaunchData; |
26 | - console.log("启动信息", JSON.stringify(launchData)); | |
26 | + console.log("启动信息", launchData); | |
27 | 27 | let { query, scene, referrerInfo } = launchData; |
28 | 28 | let { |
29 | 29 | invite_type, |
... | ... | @@ -41,7 +41,6 @@ export default class WxInit { |
41 | 41 | // 抖音投放相关信息 |
42 | 42 | clue_token, |
43 | 43 | ad_id, |
44 | - promotion_id, | |
45 | 44 | creative_id, |
46 | 45 | advertister_id, |
47 | 46 | request_id |
... | ... | @@ -59,10 +58,6 @@ export default class WxInit { |
59 | 58 | if (ad_id) { |
60 | 59 | fromChannel = ad_id; |
61 | 60 | } |
62 | - // 设置抖音投放转化跟踪 v2 | |
63 | - if(promotion_id){ | |
64 | - fromChannel = promotion_id; | |
65 | - } | |
66 | 61 | |
67 | 62 | //定向分享统计 |
68 | 63 | if (shareMessageToFriendScene && shareMessageToFriendScene >= 0 && shareMessageToFriendScene <= 50) { | ... | ... |
wxsdk/wx/WxLaunch.ts
... | ... | @@ -3,7 +3,8 @@ export default class WxLaunch { |
3 | 3 | private data: LaunchInfoSyncReturnValue; |
4 | 4 | |
5 | 5 | private constructor() { |
6 | - this.data = wx.getLaunchOptionsSync(); | |
6 | + this.data = my.getLaunchOptionsSync(); | |
7 | + // console.log('lauch--',this.data); | |
7 | 8 | } |
8 | 9 | |
9 | 10 | get LaunchData() { | ... | ... |
wxsdk/wx/WxLogin.ts
... | ... | @@ -8,7 +8,7 @@ import LogService from "../service/LogService"; |
8 | 8 | import { DOT_SHARE_TYPE } from "../base/SDKEnum"; |
9 | 9 | import ShareVideoService from "../service/ShareVideoService"; |
10 | 10 | import OnlineService from "../service/OnlineService"; |
11 | -import AlipayApi from "../alipay/AlipayApi"; | |
11 | +import AlipayApi from '../alipay/AlipayApi'; | |
12 | 12 | |
13 | 13 | export default class WxLogin { |
14 | 14 | /** |
... | ... | @@ -18,21 +18,25 @@ export default class WxLogin { |
18 | 18 | * tip2:必须先调用wxLogin才能使用getUserInfo |
19 | 19 | */ |
20 | 20 | async login(isAuthorize: boolean): Promise<any> { |
21 | - if (typeof my !== 'undefined') { | |
21 | + | |
22 | + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { | |
23 | + return | |
24 | + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { | |
25 | + let self = this; | |
22 | 26 | return new Promise(async (resolve, reject) => { |
23 | - console.log("-----login4-------") | |
24 | - let code = await AlipayApi.I.login(); | |
25 | - console.log("-----login5-------") | |
26 | - console.log(code) | |
27 | 27 | if (isAuthorize) { |
28 | 28 | AlipayApi.I.getUserinfo() |
29 | - .then((ret: any) => this.authedlogin(ret, code, resolve, reject)) | |
30 | - .catch((err: any) => this.weakLogin(err, code, resolve, reject)); | |
29 | + .then((ret: any) => this.authedlogin(ret, ret.authCode, resolve, reject)) | |
30 | + .catch(async (err: any) => { | |
31 | + let code = await AlipayApi.I.login(); | |
32 | + self.weakLogin(err, code, resolve, reject); | |
33 | + }); | |
31 | 34 | } else { |
32 | - this.weakLogin({ errCode: 1, msg: '默认未授权登录' }, code, resolve, reject) | |
35 | + let code = await AlipayApi.I.login(); | |
36 | + self.weakLogin({ errCode: 1, msg: '默认未授权登录' }, code, resolve, reject) | |
33 | 37 | } |
34 | 38 | }); |
35 | - } else { | |
39 | + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { | |
36 | 40 | return new Promise(async (resolve, reject) => { |
37 | 41 | let code = await WxApi.I.login(); |
38 | 42 | if (isAuthorize) { |
... | ... | @@ -107,9 +111,7 @@ export default class WxLogin { |
107 | 111 | * @param isAuthorize 是否授权:true=已授权 false=没有授权成功 |
108 | 112 | */ |
109 | 113 | private handleLogin(data: any, resolve: any, isAuthorize: boolean) { |
110 | - // console.log("登录请求结果data", data) | |
111 | - | |
112 | - console.log("-----login5-------") | |
114 | + console.log("登录请求结果data"+JSON.stringify(data)) | |
113 | 115 | if (data) { |
114 | 116 | // 设置登录信息 |
115 | 117 | if (data.data) { |
... | ... | @@ -135,13 +137,11 @@ export default class WxLogin { |
135 | 137 | } |
136 | 138 | try { //修改时间后会报错,未找到原因 |
137 | 139 | this.handleExpire(expire) |
140 | + // 支付宝会报错,如有自定义分享请解决 | |
141 | + // ShareVideoService.I.forward() | |
138 | 142 | } catch (error) { |
139 | 143 | console.log("handleExpire_error", error) |
140 | 144 | } |
141 | - // 支付宝没有 | |
142 | - if(typeof my == 'undefined'){ | |
143 | - ShareVideoService.I.forward() | |
144 | - } | |
145 | 145 | } |
146 | 146 | } |
147 | 147 | resolve(data) |
... | ... | @@ -209,11 +209,7 @@ export default class WxLogin { |
209 | 209 | refToken: reftoken, |
210 | 210 | expire, |
211 | 211 | }); |
212 | - try { //修改时间后会报错,未找到原因 | |
213 | - this.handleExpire(expire) | |
214 | - } catch (error) { | |
215 | - console.log("handleExpire_error", error) | |
216 | - } | |
212 | + this.handleExpire(expire) | |
217 | 213 | }) |
218 | 214 | } |
219 | 215 | ... | ... |
wxsdk/wx/WxPay.ts
... | ... | @@ -23,8 +23,7 @@ export default class WxPay { |
23 | 23 | offerId: OfferId, |
24 | 24 | currencyType: CurrencyType, |
25 | 25 | buyQuantity: params.money / 10, |
26 | - zoneId: ZoneId, | |
27 | - outTradeNo:params.orderid | |
26 | + zoneId: ZoneId | |
28 | 27 | }; |
29 | 28 | let extend = ""; |
30 | 29 | for (let key in opts) { |
... | ... | @@ -49,7 +48,7 @@ export default class WxPay { |
49 | 48 | WxApi.I.requestMidasPayment(pms) |
50 | 49 | .then(() => this.handlePaySuccess({ ...params, platform }, opts, resolve, reject)) |
51 | 50 | .catch(err => this.handlePayError({ ...params, platform }, opts, err, reject)); |
52 | - } else { | |
51 | + }else{ | |
53 | 52 | reject(res); |
54 | 53 | } |
55 | 54 | }) |
... | ... | @@ -91,7 +90,7 @@ export default class WxPay { |
91 | 90 | } |
92 | 91 | |
93 | 92 | private handlePayError(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts, err: any, reject: any) { |
94 | - console.log("handlePayError支付失败", JSON.stringify(err)); | |
93 | + console.log("支付失败", JSON.stringify(err)); | |
95 | 94 | let type = 2; |
96 | 95 | if (err.errCode + '' == '1') { |
97 | 96 | type = 3; | ... | ... |
wxsdk/wx/WxSystem.ts
... | ... | @@ -3,7 +3,8 @@ export default class WxSystem { |
3 | 3 | private data: SystemInfoSyncReturnValue; |
4 | 4 | |
5 | 5 | private constructor() { |
6 | - this.data = wx.getSystemInfoSync(); | |
6 | + this.data = my.getSystemInfoSync(); | |
7 | + // console.log('WxSystem',this.data) | |
7 | 8 | } |
8 | 9 | |
9 | 10 | get SystemData() { |
... | ... | @@ -42,7 +43,8 @@ export default class WxSystem { |
42 | 43 | } |
43 | 44 | |
44 | 45 | get SDKVersion() { |
45 | - return this.data.SDKVersion || this.data.version; | |
46 | + //version 是支付宝返回的 | |
47 | + return this.data.SDKVersion||this.data.version; | |
46 | 48 | } |
47 | 49 | |
48 | 50 | get brand() { | ... | ... |