diff --git a/sdk/Analytics.ts b/sdk/Analytics.ts index 2386d57..b83c589 100644 --- a/sdk/Analytics.ts +++ b/sdk/Analytics.ts @@ -1,12 +1,10 @@ -import TAMgr from "../../framework/ta/TAMgr"; -import { SDKLogLevel } from "../../framework/wxsdk/service/LogService"; -import WXSDK from "../../framework/wxsdk/WXSDK"; - +import { LogLevel } from "../wxsdk/service/LogService"; +import WXSDK from "../wxsdk/WXSDK"; export class Analytics { private static _instance: Analytics; - private systemType: number; + private systemType: number static get I(): Analytics { return this._instance || (this._instance = new Analytics); } @@ -22,14 +20,8 @@ export class Analytics { // 游戏打点 dot(dot_type: string, data: any = {}) { - if (typeof wx == 'undefined'&&typeof my == 'undefined') { - console.log("dot", dot_type, data); - return - } - // 数数 - 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 - TAMgr.Ins.dot(dot_type, data); - } + if (typeof my == 'undefined') return + // wx.aldSendEvent(dot_type, data); //阿拉丁打点,没需求注释即可 return WXSDK.stat.dot(dot_type, data); } @@ -52,7 +44,9 @@ export class Analytics { * @param stagename 关卡名称,格式:"xx模式-第x关" * @param pattern 模式名称,格式:"xx模式" */ - levelStart(stageid, stagename, pattern) { + levelStart(stageid, stagename?, pattern?) { + if (!stagename) stagename = `第${stageid}关` + if (!pattern) pattern = '普通模式' return WXSDK.stat.levelStart(stageid, stagename, pattern) } /** @@ -67,6 +61,8 @@ export class Analytics { * @param params_desc 道具描述 */ levelRunning(stageid, stagename, pattern, event, params_id, params_name, params_count, params_desc?) { + if (!stagename) stagename = `第${stageid}关` + if (!pattern) pattern = '普通模式' return WXSDK.stat.levelRunning(stageid, stagename, pattern, event, params_id, params_name, params_count, params_desc) } /** @@ -78,8 +74,10 @@ export class Analytics { * @param times 时间 * @param perc 失败时的完成进度 (浮点数) */ - async levelEnd(stageid, stagename, pattern, event, times, perc?) { - return WXSDK.stat.levelEnd(stageid, stagename, pattern, event, times, perc) + async levelEnd(stageid, stagename, pattern, event, times, perc?, valence = 0) { + if (!stagename) stagename = `第${stageid}关` + if (!pattern) pattern = '普通模式' + return WXSDK.stat.levelEnd(stageid, stagename, pattern, event, times, perc,valence) } @@ -90,7 +88,7 @@ export class Analytics { * @param level 日志等级 * @returns */ - clientLog(content, level = SDKLogLevel.debug) { + clientLog(content, level = LogLevel.debug) { return WXSDK.stat.clientLog(content, level) } /** @@ -103,18 +101,14 @@ export class Analytics { consume(id: number, typ: number, nums: number, gsne: string) { return WXSDK.stat.consume(id, typ, nums, gsne) } - /** - * loading上报 - * @param typ 1开始加载、2加载进行中、3加载结束 - * @param stageid 加载id - * @param stagename 加载内容 - * @param event complete:成功 fail:失败 - * @param times 加载消耗时间 单位毫秒 - * @param perc 完成度 - */ - loading(typ: string, stageid: string, stagename: string, event: string, times: string, perc?: number) { - return WXSDK.stat.loading(typ, stageid, stagename, event, times, perc) - } -} \ No newline at end of file +} +export enum EventKey { + toggleScene = 'toggleScene', + recoverGame = 'recoverGame', + replayGame = 'replayGame', + settingClose = 'settingClose', + updateLvUI = 'updateLvUI', + +} diff --git a/sdk/GameServicePlus.ts b/sdk/GameServicePlus.ts deleted file mode 100644 index f0e919e..0000000 --- a/sdk/GameServicePlus.ts +++ /dev/null @@ -1,377 +0,0 @@ -import DataService from "../../framework/wxsdk/service/DataService"; -import GameService from "../../framework/wxsdk/service/GameService"; -import WxPay from "../../framework/wxsdk/wx/WxPay"; -import SDKApiPlus from "./SDKApiPlus"; - - - -export default class GameServicePlus extends GameService { - memberSave(content: string, params: any = {}) { - return SDKApiPlus.memberSave({ uid: DataService.I.UserId, token: DataService.I.Token, content, ...params }); - } - - memberGet() { - return SDKApiPlus.memberGet({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - memberSesetAup() { - return SDKApiPlus.memberSesetAup({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - - memberClear() { - return SDKApiPlus.memberClear({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - - getGameNotice() { - return SDKApiPlus.notice(); - } - - mail() { - return SDKApiPlus.mail({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - - /** - * 改变邮件状态 - * @param id id为0或不传id时为 一键领取、一键删除 - * @param status 1已读 2领取 3删除。如同时修改多个状态格式:1,2 - * @returns - */ - updateMailStatus(id: number, status: string) { - return SDKApiPlus.mailStatus({ id, status, uid: DataService.I.UserId, token: DataService.I.Token }); - } - - getQRcode() { - return SDKApiPlus.QRcode(); - } - - convertCDkey(cdkey: string) { - return SDKApiPlus.cdkey({ uid: DataService.I.UserId, token: DataService.I.Token, cdkey: cdkey }); - } - - clearData() { - return SDKApiPlus.clearData({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - - goodsList() { - return SDKApiPlus.goodsList({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - - createOrder(goodid: string) { - return SDKApiPlus.createOrder({ uid: DataService.I.UserId, token: DataService.I.Token, goodid }); - } - - queryOrder(no: string) { - return SDKApiPlus.queryOrder({ uid: DataService.I.UserId, token: DataService.I.Token, no }); - } - - confirmOrder(no: string) { - return SDKApiPlus.confirmOrder({ uid: DataService.I.UserId, token: DataService.I.Token, no }); - } - - /** - * 支付 - * @param params - * @param opts - * @returns - */ - pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}) { - return WxPay.I.pay(params, opts); - } - /** - * 订单查询 - */ - orderQuery(source) { - return SDKApiPlus.orderQuery({ - ...this.buildParams(), - source - }); - } - /** - * 订单查询 - */ - preorder(goodid: string, orderid: string) { - return SDKApiPlus.preorder({ - ...this.buildParams2(), - token: DataService.I.Token, - goodid, orderid - }); - } - - /** - * 获取玩家历史存档 - * @param uid - * @param token - */ - getUserHistory(uid: string, token: string) { - return SDKApiPlus.getUserHistory({ uid: uid, token: token }); - } - - /** - * 获取玩家历史存档 - * @param data //需要包含uid,token - */ - saveUserHistory(data: any) { - return SDKApiPlus.saveUserHistory(data); - } - - /** - * 重置GM标识 - */ - setAup(typ: number = 0) { - return SDKApiPlus.setAup({ uid: DataService.I.UserId, token: DataService.I.Token, typ }); - } - - /** - * 获取分享图片 - * @param items 2,1,0|3,1,1|3,1,1|3,1,1|3,1,1格式:2,1,0(类型,id,领取状态)领取状态:1已领取0未领取 - * @param zoom 图片缩放比例 - * @returns - */ - getShareImage(items: string, zoom: number = 1) { - return SDKApiPlus.getShareImg({ uid: DataService.I.UserId, token: DataService.I.Token, items, zoom }); - } - - /** - * 获取我的今日分享 - * @param refresh 是否刷新 - */ - getShare(refresh?: number) { - let req = { uid: DataService.I.UserId, token: DataService.I.Token }; - if (refresh) { - req['refresh'] = refresh; - } - return SDKApiPlus.getShare(req); - } - - /** - * 获取好友分享详情 - * @param id 分享id - * @param date 分享日期 格式:20220524 - */ - getShareInfo(id: number, date: string) { - return SDKApiPlus.getShareInfo({ uid: DataService.I.UserId, token: DataService.I.Token, id, date }); - } - - /** - * 领取好友分享 - * @param id 分享id - * @param date 分享日期 格式:20220524 - * @param itemid 分享选项ID - */ - getShareReward(id: number, date: string, itemid: number) { - return SDKApiPlus.receiveShare({ uid: DataService.I.UserId, token: DataService.I.Token, id, date, itemid }); - } - - /** - * 领取额外进度奖励 - * @param id 分享id - * @param date 分享日期 格式:20220524 - */ - getProgressReward(id: number, date: string) { - return SDKApiPlus.getProgressReward({ uid: DataService.I.UserId, token: DataService.I.Token, id, date }); - } - - saveStory(key: string, data: string) { - // return SDKApiPlus.saveStory({ - // id: UserManager.I.curStory.id, - // lv: UserManager.I.curStory.lv, - // fbid: UserManager.I.curStory.fbid, - // fbindex: UserManager.I.curStory.fbindex, - // data, - // uid: DataService.I.UserId, - // token: DataService.I.Token, - // }); - } - - /** - * 我的邀请详情 - * @returns - */ - getInviteInfo() { - return SDKApiPlus.getInviteInfo({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - - /** - * 领取邀请奖励 - * @param id 挡位id - */ - receiveInvite(id: number) { - return SDKApiPlus.receiveInvite({ uid: DataService.I.UserId, token: DataService.I.Token, id }); - } - - /** - * 心跳 - */ - beatheart() { - return SDKApiPlus.heartbeat({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - /** - * 周卡/月卡列表 - */ - recCardList() { - return SDKApiPlus.recCardList({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - - /** - * 领取周卡/月卡奖励 - * @param typ 第几天 week周 month月 - */ - recCardReward(typ: string) { - return SDKApiPlus.recCardReward({ uid: DataService.I.UserId, token: DataService.I.Token, typ }); - } - - /** - * 领取基金列表 - */ - recGrowthList() { - return SDKApiPlus.recGrowthList({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - - /** - * 领取基金列表 - * @param goodid 购买的基金商品ID - * @param level 等级 - */ - recGrowthReward(goodid: string, level: number) { - return SDKApiPlus.recGrowthReward({ uid: DataService.I.UserId, token: DataService.I.Token, goodid, level }); - } - - /** - * 获取无尽礼包数据 - */ - recEndlessList(groupId: string) { - return SDKApiPlus.recEndlessList({ uid: DataService.I.UserId, token: DataService.I.Token, group_id: groupId }); - } - - /** - * 领取无尽礼包 - */ - recEndlessReward(groupId: string, id: string, date: string) { - return SDKApiPlus.recEndlessReward({ uid: DataService.I.UserId, token: DataService.I.Token, group_id: groupId, id, date }); - } - - /** - * 获取新手礼包数据 - */ - getNewbieGiftData() { - return SDKApiPlus.getNewbieGiftData({ uid: DataService.I.UserId, token: DataService.I.Token }); - } - - /** - * 领取新手礼包 - * @param days 第几天 - */ - recNewbieGift(days: string) { - return SDKApiPlus.recNewbieGift({ uid: DataService.I.UserId, token: DataService.I.Token, days }); - } - - - /** - * 订阅消息 - * @param tmplId 订阅ID - * @param message 订阅内容 - * @param sendtime 订阅发送时间s二选一参数 - * @param times 订阅延迟时间s二选一参数 - * @param status 1取消以前相同模板信息,默认为0不取消 - */ - async sendSubScribe(tmplId: string, message: string, sendtime: number, times: number = 0, status: number = 1) { - let uid = +DataService.I.UserId; - let token = DataService.I.Token + ''; - let openid = DataService.I.OpenId + ''; - - let data = { - uid, - token, - openid, - status, - message: encodeURIComponent(message), - temid: tmplId - }; - if (times) { - data["times"] = times; - } else { - data["sendtime"] = Math.floor(sendtime); - } - let back = await SDKApiPlus.sendsubscribe(data) - return back; - } - - - /** - * 取消订阅消息 - * @param tmplId 订阅ID - */ - async cancelSubscribe(tmplId: string) { - let uid = +DataService.I.UserId; - let token = DataService.I.Token + ''; - let openid = DataService.I.OpenId + ''; - - let data = { - uid, - token, - openid, - temid: tmplId - }; - let back = await SDKApiPlus.cancelSubscribe(data) - return back; - } - /** - * 自定义活动 - * @param id 活动ID(后台的ID) - */ - activityCustom(id?: string) { - return SDKApiPlus.activityCustom({ id }); - } - - /** - * 添加排行榜 - * @param typ 游戏端自定义排行标识 - * @param fraction 分数 如果上报的分数小于以前上报的分数,则不会更新 - * @param rankData 扩展字段 - * @returns - */ - rankAddV2(typ: string, fraction: number, rankData?: string) { - return SDKApiPlus.rankAddV2({ typ, fraction, rankData, uid: DataService.I.UserId, token: DataService.I.Token }); - } - /** - * 排行榜列表 - * @param percent percent等于1 的时候会返回排行榜总人数和自己的当前排名 - */ - rankListV2(typ: string, percent: number = 0) { - return SDKApiPlus.rankListV2({ typ, percent, uid: DataService.I.UserId, token: DataService.I.Token }); - } - /** - * 活动排行榜配置 - * @param name 游戏端自定义排行标识 - */ - activityRankConfig(name: string) { - return SDKApiPlus.activityRankConfig({ name, uid: DataService.I.UserId, token: DataService.I.Token }); - } - /** - * 活动排行榜添加分数 - * @param name 游戏端自定义排行标识 - * @param score 分数 - * @param extend 扩展 - */ - activityRankAdd(name: string, score: number, extend: string) { - return SDKApiPlus.activityRankAdd({ name, score, extend, uid: DataService.I.UserId, token: DataService.I.Token }); - } - /** - * 活动排行榜 - * @param name 游戏端自定义排行标识 - */ - activityRankList(name: string) { - return SDKApiPlus.activityRankList({ name, uid: DataService.I.UserId, token: DataService.I.Token }); - } - /** - * 活动排行榜奖励 - * @param name 游戏端自定义排行标识 - */ - activityRankReward(name: string) { - return SDKApiPlus.activityRankReward({ name, uid: DataService.I.UserId, token: DataService.I.Token }); - } - - static instance: GameServicePlus; - static get I(): GameServicePlus { - return this.instance || (this.instance = new GameServicePlus()); - } -} \ No newline at end of file diff --git a/sdk/Ge.ts b/sdk/Ge.ts deleted file mode 100644 index 9781ec2..0000000 --- a/sdk/Ge.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { sys } from "cc"; -import { GAMEDATA } from "../../framework/wxsdk/base/SDKConst"; -import { SDKToolsPlus } from "./SDKToolsPlus"; - - - -export class Ge { - private static _instance: GravityAnalyticsAPI; - static get I(): GravityAnalyticsAPI { - return this._instance; - } - constructor() { - } - - public static init() { - // console.log("ge初始化") - const config = { - accessToken: "ihcpiWLHTqDs5oZEGsnyxCrFXBaSeoju", // 项目通行证,在:网站后台-->管理中心-->应用列表中找到Access Token列 复制(首次使用可能需要先新增应用) - clientId: SDKToolsPlus.openId, // 用户唯一标识,如微信小程序的openid - autoTrack: { - appLaunch: true, // 自动采集 $MPLaunch - appShow: true, // 自动采集 $MPShow - appHide: true, // 自动采集 $MPHide - }, - name: "ge", // 全局变量名称 - // debugMode: "debug", // 是否开启测试模式,开启测试模式后,可以在 网站后台--管理中心--元数据--事件流中查看实时数据上报结果。(测试时使用,上线之后一定要关掉,改成none或者删除) - }; - let ge = new GravityAnalyticsAPI(config); - ge.init(); - let isFirst = sys.localStorage.getItem('tt_register'); - if (!isFirst) { - // 首次注册 - let arr = GAMEDATA.version.split("."); - let version = +(arr[0] + arr[1] + arr[2]); - ge.register({ - name: SDKToolsPlus.uid, - version, - wx_openid: SDKToolsPlus.openId, - wx_unionid: "", - }).then((success) => { - // console.log("注册成功", success); - sys.localStorage.setItem('tt_register', "1") - }).catch((fail) => { - // console.error("注册失败", fail) - }) - } - this._instance = ge; - } - -} \ No newline at end of file diff --git a/sdk/SDKApiPlus.ts b/sdk/SDKApiPlus.ts deleted file mode 100644 index 8a34960..0000000 --- a/sdk/SDKApiPlus.ts +++ /dev/null @@ -1,144 +0,0 @@ -import { SDKApi } from "../../framework/wxsdk/http/SDKApi"; -import DataService from "../../framework/wxsdk/service/DataService"; -import SDKHttpPlus from "./SDKHttpPlus"; - -export default class SDKApiPlus extends SDKApi { - //公告 - public static notice = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.notice, ...args); - //订阅 - public static sendsubscribe = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.sendsubscribe, ...args); - //取消订阅 - public static cancelSubscribe = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.cancelSubscribe, ...args); - //邮件 - public static mail = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.mail, ...args); - //邮件状态修改 - public static mailStatus = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.mailStatus, ...args); - //群二维码 - public static QRcode = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.QRcode, ...args); - //兑换码 - public static cdkey = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.cdkey, ...args); - //删除存档 - public static clearData = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.clearData, ...args); - //商品列表 - public static goodsList = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.goodsList, ...args); - //生成订单 - public static createOrder = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.createOrder, ...args); - //查询订单 - public static queryOrder = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.queryOrder, ...args); - //确认订单 - public static confirmOrder = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.confirmOrder, ...args); - //重置GM标识 - public static setAup = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.setAup, ...args); - //获取分享图片 - public static getShareImg = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getShareImg, ...args); - //获取今日分享 - public static getShare = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getShare, ...args); - //获取分享信息 - public static getShareInfo = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getShreInfo, ...args); - //领取好友分享 - public static receiveShare = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.receiveShare, ...args); - //领取分享额外奖励 - public static getProgressReward = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getProgressReward, ...args); - //保存副本 - public static saveStory = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.saveStory, ...args); - //我的邀请详情 - public static getInviteInfo = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getInviteInfo, ...args); - //领取邀请奖励 - public static receiveInvite = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.receiveInvite, ...args); - - // 保存用户数据 - public static memberSave = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.memberSave, ...args); - // 获取用户数据 - public static memberGet = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.memberGet, ...args); - // 重置修改标识 - public static memberSesetAup = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.memberSesetAup, ...args); - // 清除用户数据 - public static memberClear = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.memberClear, ...args); - //心跳 - public static heartbeat = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.memberXT, ...args); - //自定义活动 - public static activityCustom = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.activityCustom, ...args); - public static rankAddV2 = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.rankAddV2, ...args); - public static rankListV2 = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.rankListV2, ...args); - - //周卡/月卡列表 - public static recCardList = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recCardList, ...args); - //领取周卡/月卡奖励 - public static recCardReward = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recCardReward, ...args); - //领取基金列表 - public static recGrowthList = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recGrowthList, ...args); - //领取基金奖励 - public static recGrowthReward = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recGrowthReward, ...args); - //获取无尽礼包数据 - public static recEndlessList = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recEndlessList, ...args); - //领取无尽礼包 - public static recEndlessReward = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recEndlessReward, ...args); - //获取新手礼包数据 - public static getNewbieGiftData = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.getNewbieGiftData, ...args); - //领取新手礼包 - public static recNewbieGift = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.recNewbieGift, ...args); - - // 活动排行榜相关 - public static activityRankConfig = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.activityRankConfig, ...args); - public static activityRankAdd = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.activityRankAdd, ...args); - public static activityRankList = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.activityRankList, ...args); - public static activityRankReward = (...args) => SDKHttpPlus.httpPost(DataService.I.GameApi, HostKeysPlus.activityRankReward, ...args); - - //后台 - public static getUserHistory = (...args) => SDKHttpPlus.backPost(DataService.I.GMApi, HostKeysPlus.getUserHistory, ...args); - public static saveUserHistory = (...args) => SDKHttpPlus.backPost(DataService.I.GMApi, HostKeysPlus.saveUserHistory, ...args); -} - - -export const HostKeysPlus = { - sendsubscribe: 'api/subscribe/event', //订阅 - cancelSubscribe: 'api/subscribe/event/cancel', //取消订阅 - notice: 'mods/notice/list', //公告 - mail: 'mods/mail/list', //邮件 - mailStatus: '/mods/mail/status/u', //修改邮件状态 - QRcode: 'game/merge/system', //群二维码 - cdkey: 'game/merge/cdkey', //兑换CDkey - clearData: 'game/merge/clear', //删除存档 - goodsList: 'game/merge/goodslist', //商品列表 - createOrder: 'game/merge/order/create', //生成订单 - queryOrder: 'game/merge/order/query', //查询订单 - confirmOrder: 'game/merge/order/give', //确认订单 - setAup: 'game/merge/aup', //重置GM标识 - getShareImg: 'game/merge/share/getimg', //分享图片 - getShare: 'game/merge/share/get', //获取今日分享(自己的) - getShreInfo: 'game/merge/share/info', //获取分享详情(别人的) - receiveShare: 'game/merge/share/receive', //领取分享奖励 - getProgressReward: 'game/merge/share/reward/progress', //获取分享奖励 - saveStory: 'game/merge/cp/save', //保存副本 - getInviteInfo: 'api/member/invite/info', //获取邀请信息 - receiveInvite: 'api/member/invite/receive', //领取邀请奖励 - - memberSave: 'yueliangdao/member/save', //存用户数据 - memberGet: 'yueliangdao/member/get', //取用户数据 - memberSesetAup: 'yueliangdao/member/reset/aup', //重置修改标识 - memberClear: '3ad7e4ab92ae2249/member/clear', //清除用户数据 4.11改 - memberXT: 'yueliangdao/member/xt', //心跳 - activityCustom: 'mods/activity/custom', //自定义活动 - rankListV2: 'mods/rank/permanent/list', //排行榜2023-4-24 - rankAddV2: 'mods/rank/permanent/add', //更新排行榜2023-4-24 - - - recCardList: '3ad7e4ab92ae2249/member/ship/info', //周卡/月卡列表 - recCardReward: '3ad7e4ab92ae2249/member/ship/draw', //领取周卡/月卡奖励 - recGrowthList: 'game/merge/growth/list', //领取基金列表 - recGrowthReward: 'game/merge/growth/rec', //领取基金奖励 - recEndlessList: '3ad7e4ab92ae2249/egift/show', //获取无尽礼包数据 - recEndlessReward: '3ad7e4ab92ae2249/egift/draw', //领取无尽礼包 - getNewbieGiftData: '3ad7e4ab92ae2249/novice/list', //获取新手礼包数据 - recNewbieGift: '3ad7e4ab92ae2249/novice/draw', //领取新手礼包 - - activityRankConfig: 'yueliangdao/activities/rank/config', //活动排行榜配置 - activityRankAdd: 'yueliangdao/activities/rank/add', //活动排行榜添加分数 - activityRankList: 'yueliangdao/activities/rank/top', //活动排行榜 - activityRankReward: 'yueliangdao/activities/rank/draw', //活动排行榜奖励 - - - //后台 - getUserHistory: 'index/merge/history.html', //获取用户历史存档 - saveUserHistory: 'index/merge/setdata.html', //覆盖用户数据 -} diff --git a/sdk/SDKHttpPlus.ts b/sdk/SDKHttpPlus.ts deleted file mode 100644 index df35708..0000000 --- a/sdk/SDKHttpPlus.ts +++ /dev/null @@ -1,139 +0,0 @@ -import { DEBUG } from "cc/env"; -import { GAMEDATA, sdkEnv } from "../../framework/wxsdk/base/SDKConst"; -import SDKHttp from "../../framework/wxsdk/http/SDKHttp"; -import { WxHelper } from "./WxHelper"; -import LogService from "../../framework/wxsdk/service/LogService"; -import DataService from "../../framework/wxsdk/service/DataService"; - -sdkEnv.isDebug = DEBUG; -export default class SDKHttpPlus extends SDKHttp { - - public static async backRequest(url: string, method: string, data?: any, dataType: "json" | "string" = "json") { - return new Promise>((resolve, reject) => { - data = { - ...data, - gameid: GAMEDATA.game_id, - } - - if (data && typeof data === "object") { - data = JSON.stringify(data); - } - data = data || ""; - if (method == "GET" && data != "") { - data = JSON.parse(data); - let str = '' - for (let key in data) { - str = str + `${key}` + '=' + `${data[key]}&` - } - url += "?" + str; - data = ""; - } - // let info = "[url:" + url + ", data:" + data + "]"; - // console.error("info", info) - let xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function () { - if (xhr.readyState == 4) { - if (xhr.status >= 200 && xhr.status < 400) { - let responseText: any = xhr.responseText; - // cc.log("responseText", responseText) - try { - responseText = JSON.parse(responseText); - // cc.log("responseText22", responseText) - if (url.indexOf('.json') > -1) { - resolve({ code: 0, data: responseText, msg: responseText.msg }); - } else { - resolve({ code: +responseText.code, data: responseText.data, msg: responseText.msg }); - } - return - } catch (ex) { - // console.error("httpRequest[parseError]:responseText=" + xhr.responseText); - resolve({ msg: "JSON parse error:" + ex.message, code: -1 }); - return; - } - } else { - console.error(xhr.status, '网络请求失败!'); - resolve({ code: -2 }); - } - } - }; - - xhr.ontimeout = function (info): void { - console.error("info1", info) - resolve({ msg: `请求超时!`, code: -3 }); - } - xhr.onerror = function (info): void { - console.error("info2", info) - resolve({ msg: `请求失败!`, code: -4 }); - } - xhr.onabort = function (info): void { - console.error("info3", info) - resolve({ msg: `请求关闭!`, code: -5 }); - } - - xhr.timeout = 30000; - xhr.open(method, url, true); - - if (method == "POST") { - xhr.setRequestHeader("Content-Type", "application/json;charset=utf-8")//application/x-www-form-urlencoded - // if (cc.sys.os === 'Android') { - // cc.error("http__uid", AppSdkData.I.uid); - // xhr.setRequestHeader('Uuid', `${AppSdkData.I.uid}`); - // } else { - // xhr.setRequestHeader('Uuid', `909`); - // } - - } - console.log("data", data) - xhr.send(data); - }); - } - - public static async backGet(baseUrl: string, url: string, data?: any, dataType: "json" | "string" = "json") { - if (this.withMock(url)) { - return this.mockData(url); - } - - url = baseUrl + url; - return this.backRequest(url, "GET", data, dataType); - } - - public static backPost(baseUrl: string, url: string, data?: any, dataType: "json" | "string" = "json") { - if (this.withMock(url)) { - return this.mockData(url); - } - - url = baseUrl + url; - return this.backRequest(url, "POST", data, dataType); - } -} - -SDKHttp.onErrorResponse = async function (data: any) { - console.log("onErrorResponse", data) - if (data.code > 0) { - LogService.I.dot("errCode", { form: data.code + "_" + DataService.I?.Data?.userId }) - } else { - LogService.I.dot("errCode", { form: data.code }) - } - if (data.code == 1008) { - let ret = await WxHelper.showModal({ - title: '登录验证失败,请重新登录', - content: data.msg, - showCancel: false, - confirmText: '重启' - }) - if (ret) { - WxHelper.restartMiniProgram(); - } - } - if (data.code == 1011000) { - let ret = await WxHelper.showModal({ - title: '数据被修改', - content: data.msg, - showCancel: false, - confirmText: '重启' - }) - if (ret) { - WxHelper.restartMiniProgram(); - } - } -}; \ No newline at end of file diff --git a/sdk/SDKTools.ts b/sdk/SDKTools.ts index 211be1a..dc36e7c 100644 --- a/sdk/SDKTools.ts +++ b/sdk/SDKTools.ts @@ -1,16 +1,13 @@ -import { GAMEDATA } from "../../framework/wxsdk/base/SDKConst"; -import DateUtils from "../../framework/wxsdk/utils/DateUtils"; -import WXSDK from "../../framework/wxsdk/WXSDK"; - +import AlipayApi from "../wxsdk/alipay/AlipayApi"; +import { GAMEDATA } from "../wxsdk/base/SDKConst"; +import DateUtils from "../wxsdk/utils/DateUtils"; +import WXSDK from "../wxsdk/WXSDK"; /* * SDK工具类库; */ export class SDKTools { static get isWx() { - return typeof wx !== 'undefined'; - } - static get isZfb() { return typeof my !== 'undefined'; } static get isSupported() { @@ -83,8 +80,10 @@ export class SDKTools { * isOff:是否关闭默认显示banner * } */ - static createBanner(adUnitId: string = GAMEDATA.bannerId, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean ,isCreate?:boolean}) { + static createBanner(adUnitId: string = GAMEDATA.bannerId, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { if (!this.isWx) return + // if (SDKUtils.compareVersion(my.env.clientVersion, '10.3.66') < 0) return; + // console.log('banner') return WXSDK.ad.createBanner(adUnitId, opts); } /** @@ -114,6 +113,7 @@ export class SDKTools { * 插屏 */ static createInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { + // console.log('~~~~~~~~~~chaping') if (!this.isWx) return Promise.resolve({ code: 1, msg: "暂无广告" }) return WXSDK.ad.createInterstitialAd(adUnitId); } @@ -167,9 +167,12 @@ export class SDKTools { /** * 订阅 * @param template_ids 模板id eg['aaaaaaa','bbbbbbb'] - * @param success 成功回调 - * @param fail 失败回调 + * @param ids 对应后台的id eg:['1','2'] */ + // static subScribe(template_ids: Array, ids: Array) { + // if (!this.isWx) return + // return WXSDK.game.subScribe(template_ids, ids) + // } static subScribe(template_ids: Array, success: Function, fail: Function) { if (!window['wx']) return; return WXSDK.game.subScribe(template_ids, success, fail); @@ -247,16 +250,7 @@ export class SDKTools { - /** - * 互动数据解密 - * @param iv - * @param encryptedData - * @returns - */ - static wxencrypted(iv, encryptedData): Promise> { - if (!this.isWx) return Promise.resolve({ code: -1 }) - return WXSDK.game.wxencrypted(iv, encryptedData); - } + /** * 互导数据 * 1抽屉广告2猜你喜欢3格子广告4试玩 @@ -301,7 +295,7 @@ export class SDKTools { * @returns */ static pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}) { - return WXSDK.game.pay(params, opts); + return WXSDK.game.pay(params, opts) } /** * 检测支付是否成功 @@ -342,26 +336,21 @@ export class SDKTools { return WXSDK.game.behavior() } - /** - * - * scene 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)(必填) - content 需检测的文本内容,文本字数的上限为2500字(必填) - nickname 用户昵称(非必填) - title 文本标题(非必填) - signature 个性签名,该参数仅在资料类场景有效(scene=1)(非必填) - */ - static checkmsg(scene: number, content: string, nickname?: string, title?: string, signature?: string) { - return WXSDK.game.checkmsg(scene, content, nickname, title, signature) - } + //阿里增量任务 + static incrementGameaction(action_code, success: Function, fail: Function) { + if (this.uid) { + AlipayApi.I.incrementGameaction(action_code).then((res) => { + success(); + }).catch((res) => { + fail && fail(); + }); + } else { + //登录状态过期,重进登录 + fail(); + } - /** - * 修改用户头像昵称 - */ - static updateNickname(nickname: string, headurl: string) { - return WXSDK.game.updateNickname(nickname, headurl) } - } /** diff --git a/sdk/SDKToolsPlus.ts b/sdk/SDKToolsPlus.ts deleted file mode 100644 index 538abd8..0000000 --- a/sdk/SDKToolsPlus.ts +++ /dev/null @@ -1,420 +0,0 @@ -import { sys } from "cc"; -import { EventCenter } from "../../framework/core/utils/EventCenter"; -import { EnvCode } from "../../framework/wxsdk/base/SDKEnum"; -import DataService from "../../framework/wxsdk/service/DataService"; -import { GameEvent } from "../../game/const/GameEvent"; -import GameServicePlus from "./GameServicePlus"; -import { SDKTools } from "./SDKTools"; - -export class ServerError { - private static _errors = { - "0": { msg: "成功", desc: "接口调用成功" }, - "1000": { msg: "操作失败", desc: "检查Hermes后台配置是否正确" }, - "1001": { msg: "未知错误", desc: "联系开发人员排查错误" }, - "1002": { msg: "参数错误", desc: "请参照接口文档对比参数和参数类型是否正确" }, - "1003": { msg: "签名错误", desc: "检查appkey跟后台是否对应" }, - "1004": { msg: "数据不存在", desc: "查询的数据不存在等" }, - "1005": { msg: "解析参数失败,请检查参数合法性", desc: "参数中是否有危险字符,比如SQL注入等" }, - "4500": { msg: "商品不存在", desc: "检查Hermes后台配置是否正确" }, - "4501": { msg: "订单未支付", desc: "" }, - "4502": { msg: "不能重复发放", desc: "" }, - "4503": { msg: "兑换码不存在", desc: " " }, - "4504": { msg: "兑换码不在有效期内", desc: " " }, - "4505": { msg: "兑换码已失效", desc: " " }, - "4506": { msg: "iv error", desc: "防止用户本地修改数据" }, - "4507": { msg: "数据被修改", desc: "用户数据被GM工具修改,需重新登录重置" }, - "4508": { msg: "此商品已达到最大购买限制", desc: "限购" }, - "4509": { msg: "没有上传文件", desc: "检查文件name属性是否正确" }, - "4510": { msg: "文件超出最大限制", desc: "最大1M" }, - "4511": { msg: "请先授权获取微信头像信息", desc: "登录接口获取" }, - "4513": { msg: "没有达到刷新条件", desc: "生成过一次且没有领取 才可刷新" }, - "4514": { msg: "刷新次数超限", desc: "刷新次数达到 配置最大项" }, - "4515": { msg: "分享失效", desc: "跨天失效等" }, - "4516": { msg: "分享不存在", desc: "分享ID不存在等" }, - "4517": { msg: "已被领取", desc: "被其他人领取" }, - "4518": { msg: "今日领取次数超限", desc: "今天领取的次数达到配置最大项" }, - "4519": { msg: "已领过其他选项", desc: "只能领取一个" }, - "4520": { msg: "没有达到领取条件", desc: "领取进度是否完成" }, - "4522": { msg: "只能领取自己的奖励", desc: "" }, - "1009": { msg: "您的账号已因数据异常而被封禁,如需申诉可以向微信客服反馈。", desc: "" }, - "3004": { msg: "活动已经结束", desc: "" }, - } - - private static _unknownError = { msg: "未知错误", desc: "联系开发人员排查错误" }; - static getError(code: string): { msg: string, desc: string } { - return this._errors[code] || this._unknownError; - } - - static this(key: string): string { - return (this._errors[key] || this._unknownError).msg; - } -} - -/* -* SDK工具类库; -*/ -export class SDKToolsPlus extends SDKTools { - static get isTT() { - return sys.platform == sys.Platform.BYTEDANCE_MINI_GAME; - } - - //提交订单 - static doPreorder(data, goodid: string, price: number, orderid: string) { - if (!data.code && data.data) { - let { config, paytype } = data.data; - // goodid = goodid + ""; - // console.log("支付方式"+paytype); - switch (paytype) { - case "1"://H5 客服消息支付,游戏内调用发片消息接口 sendMessagePath:path - var { img, title, path } = config; - wx.openCustomerServiceConversation({ - showMessageCard: true, //是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息 - sendMessageTitle: title ? title : '我要充值!',//会话内消息卡片标题 - sendMessagePath: path,//会话内消息卡片路径//channel=${SDKTools.ChannelId}&item=10&uid=${SDKTools.UserId} - sendMessageImg: img ? img : 'https://wxsdk-cdn.miso-lab.com/moon-island/share/fx_chongzhi.jpg',//会话内消息卡片图片路径 - success: (ret) => { - //记录状态 - //onshow检测状态,判断是否充值成功 - console.log("支付成功:", ret); - EventCenter.I.emit(GameEvent.PAY_POLLING, true); - }, - fail: (ret) => { - console.log("fail", ret); - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); - } - }) - break; - case "2": - - - break; - case "3"://米大师支付,游戏支付成功需要调用米大师订单上报接口 - var { payid } = config; - SDKTools.pay({ payid, goodid, money: price, orderid: orderid }).then(res => { - if (!res.code) { - console.log("支付成功", res); - EventCenter.I.emit(GameEvent.PAY_CONFIRM, orderid, goodid); - } else { - console.log("支付失败", res); - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); - } - }).catch(err => { - console.log("支付失败2:", err); - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); - }) - break; - case "4"://跳转小程序支付,游戏直接跳转返回的小程序路径 - var { appid, page } = config; - wx.navigateToMiniProgram({ - appId: appid, - path: page, - envVersion: DataService.I.EnvEnum === EnvCode.Prod ? 'release' : "trial",//opts.envVersion || 'release', - success(res: any) { - console.log("成功:", res) - // resolve(res); - EventCenter.I.emit(GameEvent.PAY_POLLING, true); - }, - fail(err: any) { - console.log("失败", err) - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); - // reject(err); - } - }); - break; - case "5"://扫码小程序支付,imgurl为二维码地址,提示用户扫码即可 - EventCenter.I.emit(GameEvent.PAY_POLLING, true); - var { imgurl } = config; - wx.previewImage({ - current: imgurl, // 当前显示图片的http链接 - urls: [imgurl] // 需要预览的图片http链接列表 - }) - - break; - case "6"://二维码支付,windows下需要调用扫码支付接口 - EventCenter.I.emit(GameEvent.PAY_POLLING, true); - var { qrcode } = config; - wx.previewImage({ - current: qrcode, // 当前显示图片的http链接 - urls: [qrcode] // 需要预览的图片http链接列表 - }) - - break; - case "7"://抖音支付 - var { payid } = config; - SDKTools.pay({ payid, goodid, money: price, orderid: orderid }).then(res => { - if (!res.code) { - console.log("支付成功", res); - EventCenter.I.emit(GameEvent.PAY_CONFIRM, orderid, goodid); - } else { - console.log("支付失败", res); - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); - } - }).catch(err => { - console.log("支付失败", err); - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); - }) - break; - case "10"://支付宝支付 - var { payid } = config; - SDKTools.pay({ payid, goodid, money: price, orderid: orderid }).then(res => { - if (!res.code) { - console.log("111tttttt"+Date.now()); - EventCenter.I.emit(GameEvent.PAY_POLLING_NOW, true); - } else { - console.log("支付失败", JSON.stringify(res)); - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); - } - }).catch(err => { - console.log("支付失败", JSON.stringify(err)); - EventCenter.I.emit(GameEvent.PAY_FAIL, orderid, goodid); - }) - break; - default: - // utils.tips("出错!") - break; - } - } else { - // utils.tips("出错!") - } - } - - /** - * 获取群二维码 - */ - static QRcode() { - return GameServicePlus.I.getQRcode(); - } - - /** - * 兑换CDK - */ - static convertCDkey(cdkey: string) { - return GameServicePlus.I.convertCDkey(cdkey); - } - - /** - * 商品列表 - */ - static goodsList() { - return GameServicePlus.I.goodsList(); - } - - /** - * 生成订单 - */ - static createOrder(goodid: string) { - return GameServicePlus.I.createOrder(goodid); - } - - /** - * 查询订单 - */ - static queryOrder(no: string) { - return GameServicePlus.I.queryOrder(no); - } - - /** - * 确认订单 - */ - static confirmOrder(no: string) { - return GameServicePlus.I.confirmOrder(no); - } - - /** - * 获取玩家历史存档 - */ - static getUserHistory(uid: string, token: string) { - return GameServicePlus.I.getUserHistory(uid, token); - } - - /** - * 获取玩家历史存档 - * @param data //需要包含uid,token - */ - static saveUserHistory(data: any) { - return GameServicePlus.I.saveUserHistory(data); - } - - /** - * 重置GM标识 - */ - static setAup(typ: number = 0) { - return GameServicePlus.I.setAup(typ); - } - - /** - * 获取分享图片 - * @param items 2,1,0|3,1,1|3,1,1|3,1,1|3,1,1格式:2,1,0(类型,id,领取状态)领取状态:1已领取0未领取 - * @param zoom 图片缩放比例 - * @returns - */ - static getShareImage(items: string, zoom = 1) { - return GameServicePlus.I.getShareImage(items, zoom); - } - - /** - * 获取今日分享 - * @param refresh 是否刷新 - */ - static getShare(refresh?: number) { - return GameServicePlus.I.getShare(refresh); - } - - /** - * 获取分享详情 - * @param id 分享id - * @param date 分享日期 格式:20220524 - */ - static getShareInfo(id: number, date: string) { - if (typeof id === "string") { - id = parseInt(id); - } - return GameServicePlus.I.getShareInfo(id, date); - } - - /** - * 领取好友分享 - * @param id 分享id - * @param date 分享日期 格式:20220524 - * @param itemid 分享选项ID - */ - static getShareReward(id: number, date: string, itemid: number) { - if (typeof id === "string") { - id = parseInt(id); - } - return GameServicePlus.I.getShareReward(id, date, itemid); - } - - /** - * 领取额外进度奖励 - * @param id 分享id - * @param date 分享日期 格式:20220524 - */ - static getProgressReward(id: number, date: string) { - if (typeof id === "string") { - id = parseInt(id); - } - return GameServicePlus.I.getProgressReward(id, date); - } - - static getInviteInfo() { - return GameServicePlus.I.getInviteInfo(); - } - - static receiveInvite(id: number) { - return GameServicePlus.I.receiveInvite(id); - } - - static heartbeat() { - return GameServicePlus.I.beatheart(); - } - - /** - * 领取列表 - * @param status 类型1周卡2月卡 - */ - static recCardList() { - return GameServicePlus.I.recCardList(); - } - - /** - * 领取列表 - * @param typ 第几天 week周 month月 - */ - static recCardReward(typ: string) { - return GameServicePlus.I.recCardReward(typ); - } - - /** - * 领取基金列表 - */ - static recGrowthList() { - return GameServicePlus.I.recGrowthList(); - } - - /** - * 领取基金列表 - * @param goodid 购买的基金商品ID - * @param level 等级 - */ - static recGrowthReward(goodid: string, level: number) { - return GameServicePlus.I.recGrowthReward(goodid, level); - } - - /** - * 获取无尽礼包数据 - */ - static recEndlessList(groupId: string) { - return GameServicePlus.I.recEndlessList(groupId); - } - - /** - * 领取无尽礼包 - * @param date 当前日期 - */ - static recEndlessReward(groupId: string, id: string, date: string) { - return GameServicePlus.I.recEndlessReward(groupId, id, date); - } - - /** - * 获取新手礼包数据 - */ - static getNewbieGiftData() { - return GameServicePlus.I.getNewbieGiftData(); - } - - /** - * 领取新手礼包 - * @param days 当前天 - */ - static recNewbieGift(days: string) { - return GameServicePlus.I.recNewbieGift(days); - } - - - /** - * 订阅消息 - * @param tmplId 订阅ID - * @param message 订阅内容 - * @param sendtime 订阅发送时间s二选一参数 - * @param times 订阅延迟时间s二选一参数 - * @param status 1取消以前相同模板信息,默认为0不取消 - */ - static async sendSubScribe(tmplId: string, message: string, sendtime: number, times: number = 0, status = 1) { - return GameServicePlus.I.sendSubScribe(tmplId, message, sendtime, times, status); - } - - /** - * 取消订阅消息 - * @param tmplId 订阅ID - */ - static async cancelSubscribe(tmplId: string) { - return GameServicePlus.I.cancelSubscribe(tmplId); - } - /** - * 自定义活动 - * @param id 活动ID(后台的ID) - */ - static activityCustom(id?: string) { - return GameServicePlus.I.activityCustom(id); - } - /** - * 添加排行榜 - * @param typ 游戏端自定义排行标识 - * @param fraction 分数 如果上报的分数小于以前上报的分数,则不会更新 - * @param rankData 扩展字段 - * @returns - */ - static rankAddV2(typ: string, fraction: number, rankData?: string) { - return GameServicePlus.I.rankAddV2(typ, fraction, rankData); - } - /** - * 排行榜列表 - * @param typ 游戏端自定义排行标识 - * @param percent percent等于1 的时候会返回排行榜总人数和自己的当前排名 - */ - static rankListV2(typ: string, percent: number = 0) { - return GameServicePlus.I.rankListV2(typ, percent); - } - -} \ No newline at end of file diff --git a/sdk/WxHelper.ts b/sdk/WxHelper.ts index 5bd12a6..bf714f1 100644 --- a/sdk/WxHelper.ts +++ b/sdk/WxHelper.ts @@ -1,8 +1,9 @@ // import UserManager from "../manager/UserManager"; -import { Node, UITransform, game, view } from "cc"; -import { ALIPAY } from "cc/env"; +import DataService from "../wxsdk/service/DataService"; +import AlipayApi from "../wxsdk/alipay/AlipayApi"; +import { SDKTools } from "./SDKTools"; /** WXapi */ export class WxHelper { @@ -12,19 +13,19 @@ export class WxHelper { /** 微信用户信息 */ public static userInfo: WxUserInfo; - static get isWx() { - return typeof wx !== 'undefined'; + public static get isOperable() { + return (cc.sys.platform === cc.sys.WECHAT_GAME || cc.sys.platform === cc.sys.ALIPAY_GAME) } /** 获取设备信息 */ public static getSystemInfo() { - if (this.isWx) this.SystemInfo = wx.getSystemInfoSync(); + if (typeof my !== 'undefined') this.SystemInfo = my.getSystemInfoSync(); } /** 像开放数据域发送信息 */ public static postMessage(eventType: string, data?: any): void { - if (!this.isWx || !this.checkVerison('1.9.92')) return; - wx.getOpenDataContext().postMessage({ + if (typeof my === 'undefined' || !this.checkVerison('1.9.92')) return; + my.getOpenDataContext().postMessage({ eventType: eventType, data: data }); @@ -32,17 +33,15 @@ export class WxHelper { } /** 更新微信开放数据榜单数据 */ - public static updateWxRank(key: string, value: number) { - if (typeof my != 'undefined') { - return; - } - if (!this.isWx || !this.checkVerison('1.9.92')) return; + public static updateWxRank(score: number) { + + if (typeof wx === 'undefined' || !this.checkVerison('1.9.92')) return; let data = { - value, + score: score } wx.setUserCloudStorage({ KVDataList: [{ - key, + key: 'score', value: JSON.stringify(data) }] }) @@ -50,10 +49,10 @@ export class WxHelper { } /** 创建用户反馈按钮 */ - public static createFeedbackButton(target: Node) { + public static createFeedbackButton(target: cc.Node) { let data = this.computWxPosition(target); - return wx.createFeedbackButton({ + return my.createFeedbackButton({ type: 'text', text: ' ', style: { @@ -72,10 +71,10 @@ export class WxHelper { /** 获取用户信息按钮 */ public static userInfoButton: any; /** 创建一个获取用户信息按钮 */ - public static createUserInfoButton(target: Node) { + public static createUserInfoButton(target: cc.Node) { let data = this.computWxPosition(target); // console.log("data", data) - return wx.createUserInfoButton({ + return my.createUserInfoButton({ type: 'text', text: ' ', style: { @@ -96,36 +95,33 @@ export class WxHelper { } /** 计算微信坐标 */ - public static computWxPosition(target: Node): { left: number, top: number, width: number, height: number } { + public static computWxPosition(target: cc.Node): { left: number, top: number, width: number, height: number } { let data = { left: 0, top: 0, width: 0, height: 0 } - let pos = target.worldPosition; - let width = target.getComponent(UITransform).width; - let height = target.getComponent(UITransform).height; - let ratio = view.getDevicePixelRatio(); - let scale = view.getScaleX(); + let rect = target.getBoundingBoxToWorld(); + let ratio = cc.view.getDevicePixelRatio(); + let scale = cc.view.getScaleX(); let factor = scale / ratio; - // let point = cc.v2(rect.x, rect.y); + // let point = v2(rect.x, rect.y); // point.mulSelf(scale); - data.left = (pos.x - width / 2) * factor; - data.top = wx.getSystemInfoSync().screenHeight - (pos.y + height / 2) * factor; - data.width = width * factor; - data.height = height * factor; - - // let btnSize = cc.size(target.width + 10, target.height + 10); - // let frameSize = cc.view.getFrameSize(); - // let winSize = cc.director.getWinSize(); - // // cc.log("winSize: ",winSize); - // // cc.log("frameSize: ",frameSize); + data.left = rect.x * factor; + data.top = this.SystemInfo.screenHeight - (rect.y + rect.height) * factor; + data.width = rect.width * factor; + data.height = rect.height * factor; + + // let btnSize = size(target.width + 10, target.height + 10); + // let frameSize = view.getFrameSize(); + // let winSize = director.getWinSize(); + // // log("winSize: ",winSize); + // // log("frameSize: ",frameSize); // //适配不同机型来创建微信按钮 // data.left = (winSize.width * 0.5 + target.x - btnSize.width * 0.5) / winSize.width * frameSize.width; // data.top = (winSize.height * 0.5 - target.y - btnSize.height * 0.5) / winSize.height * frameSize.height; // data.width = btnSize.width / winSize.width * frameSize.width; // data.height = btnSize.height / winSize.height * frameSize.height; - // cc.log("button pos: ",cc.v2(left,top)); - // cc.log("button size: ",cc.size(width,height)); + // log("button pos: ",v2(left,top)); + // log("button size: ",size(width,height)); - // cc.log(data) return data; } @@ -165,30 +161,10 @@ export class WxHelper { /** 显示一个对话框 */ public static showModal(data: ShowModalType) { - if (typeof my != 'undefined') { - return new Promise((resolve, reject) => { - wx.confirm({ - ...data, - success: (res: { confirm: boolean, cancel: boolean }) => { - if (res.confirm) { - resolve(true); - } else { - resolve(false); - } - }, - fail: () => { - reject(); - } - - }); - - }); - } - return new Promise((resolve, reject) => { - if (typeof wx !== 'undefined') { - wx.showModal({ + if (typeof my !== 'undefined') { + my.showModal({ ...data, success: (res: { confirm: boolean, cancel: boolean }) => { if (res.confirm) { @@ -203,7 +179,6 @@ export class WxHelper { }); } else { - console.log(JSON.stringify(data)); } }); @@ -216,41 +191,30 @@ export class WxHelper { * @param time 关闭时间 */ public static showToast(msg: string, time: number = 1500) { - if (!this.isWx) return; - if (typeof my != 'undefined') { + if (cc.sys.platform === cc.sys.WECHAT_GAME) + wx.showToast({ + title: msg, + icon: 'none', + duration: time + }) + else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { my.showToast({ type: 'none', content: msg, duration: time, }); - return; + } else { + console.log(msg) } - wx.showToast({ - title: msg, - icon: 'none', - duration: time - }) } /** 设置系统剪贴板的内容 */ public static copy(str: string) { if (!this.checkVerison('1.1.0')) return Promise.reject(''); - if (typeof my != 'undefined') { - return new Promise((resolve, reject) => { - wx.setClipboard({ - text: str, - success: (res: any) => { - resolve(res); - }, - fail: () => { - resolve(''); - } - }); - }); - } + return new Promise((resolve, reject) => { - wx.setClipboardData({ + my.setClipboardData({ data: str, success: (res: any) => { resolve(res); @@ -264,10 +228,10 @@ export class WxHelper { /** 手机发生较长时间的振动(400 ms) */ public static vibrateLong() { - if (!this.checkVerison('1.2.0')) return Promise.reject(null); + // if (!this.checkVerison('1.2.0')) return Promise.reject(null); return new Promise((resolve, reject) => { - wx.vibrateLong({ + my.vibrateLong({ success: () => { resolve(1); }, @@ -280,10 +244,10 @@ export class WxHelper { /** 手机发生较短时间的振动(15 ms) */ public static vibrateShort() { - if (!this.checkVerison('1.2.0')) return Promise.reject(null); + // if (!this.checkVerison('1.2.0')) return Promise.reject(null); return new Promise>((resolve, reject) => { - wx.vibrateShort({ + my.vibrateShort({ success: () => { resolve({ code: 0 }); }, @@ -299,13 +263,13 @@ export class WxHelper { */ public static checkUpdate(bol: boolean = true) { if (!this.checkVerison('1.9.90')) return; - const updateManager = wx.getUpdateManager(); + const updateManager = my.getUpdateManager(); updateManager.onCheckForUpdate(function (res) { console.log('updateManager', res.hasUpdate); }); updateManager.onUpdateReady(function () { - wx.showModal({ + my.showModal({ title: '更新提示', content: '新版本已经准备好,请重启应用!', showCancel: bol, @@ -326,7 +290,7 @@ export class WxHelper { return new Promise>((resolve, reject) => { if (!this.checkVerison('2.0.3')) resolve({ code: 1 }); - wx.openCustomerServiceConversation({ + my.openCustomerServiceConversation({ showMessageCard: true, sendMessageTitle: '我要更多好玩!', sendMessageImg: 'http://dep.miso-lab.com/tetrischangeskin/bin/share/concat.png', @@ -346,7 +310,7 @@ export class WxHelper { return new Promise>((resolve, reject) => { if (!this.checkVerison('2.0.3')) resolve({ code: 1 }); - wx.openCustomerServiceConversation({ + my.openCustomerServiceConversation({ success: () => { resolve({ code: 0 }); }, @@ -360,10 +324,10 @@ export class WxHelper { /** 回到前台 */ public static onShow(callback: () => void) { - if (!this.isWx) return; - wx.onShow(callback); + if (typeof my === 'undefined') return; + my.onShow(callback); // return new Promise>((resolve, reject) => { - // wx.onShow((res: any) => { + // my.onShow((res: any) => { // resolve({ code: 1 }); // }); // }); @@ -373,14 +337,14 @@ export class WxHelper { /** 切换到后台 */ public static onHide(callback: () => void) { - if (!this.isWx) return; - wx.onHide(callback); + if (typeof my === 'undefined') return; + my.onHide(callback); } public static updateShareMenu(value) { - if (!this.isWx) return; - wx.updateShareMenu({ + if (typeof my === 'undefined') return; + my.updateShareMenu({ withShareTicket: value }); } @@ -388,49 +352,18 @@ export class WxHelper { /** * 检查授权 */ - public static getSetting(scope: string = 'scope.userInfo') { - if (!this.isWx) return Promise.resolve(1); - return new Promise((resolve, reject) => { - wx.getSetting({ - success(res) { - if (res.authSetting[scope]) { - resolve(1) - } else { - reject() - } - } - }) - }) - } - /** - * 打开授权设置 - */ - public static openSetting(scope: string = 'scope.userInfo') { - if (!this.isWx) return Promise.resolve(1); - return new Promise((resolve, reject) => { - wx.openSetting({ - success(res) { - if (res.authSetting[scope]) { - resolve(1) - } else { - reject() - } - } - }) - }) - } - /** - * 打开授权窗口 - */ public static authorize(scope: string = 'scope.userInfo') { - if (!this.isWx) return; - wx.authorize({ - scope: scope, - success(suc) { - console.log("suc", suc) - }, - fail(err) { - console.log("err", err) + if (typeof my === 'undefined') return; + my.getSetting({ + success(res) { + if (!res.authSetting[scope]) { + my.authorize({ + scope: scope, + success() { + + } + }) + } } }) } @@ -438,42 +371,21 @@ export class WxHelper { * 获取用户信息 */ public static getUserInfo(callback) { - wx.getUserInfo({ - success: function (res) { - // console.log(res) - callback(res) - }, - fail: function (err) { - callback(err) - } - }) - } - /** - * 获取用户信息 自动弹出 - */ - public static getUserProfile(callback) { - if (!this.isWx) { - callback({ userInfo: "" }) - return - }; - wx.getUserProfile({ - desc: '补充用户资料', + my.getUserInfo({ success: function (res) { // console.log(res) callback(res) }, fail: function (err) { - console.log("获取用户信息", err); callback(err) } }) } /** 游戏圈 */ - public static createGameClubButton(target: Node) { + public static createGameClubButton(target: cc.Node) { let data = this.computWxPosition(target); - //@ts-ignore - return wx.createGameClubButton({ - icon: 'white', + return my.createGameClubButton({ + icon: 'green', style: { left: data.left, top: data.top, @@ -484,51 +396,65 @@ export class WxHelper { } - /** 抖音创建客服按钮 */ - public static createContactButton(target: Node) { - - let data = this.computWxPosition(target); - return wx.createContactButton({ - type: "text", // image | text - // image: "../resources/prefab/loading/mask", - text: ' ', - style: { - left: data.left, - top: data.top, - width: data.width, - height: data.height, - // lineHeight: 40, - backgroundColor: "#00000000", - // textAlign: "center", - // fontSize: 16, - // borderRadius: 5, - borderColor: "#00000000", - // borderWidth: 1, - // textColor: "#ffffff", - }, - success(res) { - console.log("createContactButton success", res); - }, - fail(res) { - console.log("createContactButton fail", res); - }, - complete(res) { - console.log("createContactButton complete", res); + public static setUserWxCloudStorage(data: object) { + if (cc.sys.platform != cc.sys.WECHAT_GAME || !DataService.I.Authorize) return null; + wx.setUserCloudStorage({ + KVDataList: [{ key: 'data', value: JSON.stringify(data) }], + success: res => { + console.log("分数上传 成功", data); }, + fail: res => { + console.log("分数上传 失败"); + } }); + } + public static showRankEnter() { + return WxHelper.isOperable && AlipayApi.I.canUseRank() + } + public static getRank(key: string) { + if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + AlipayApi.I.getRankList(key).then(() => { + console.log('success 关闭banner') + // BannerManager.I.hideAll(); + }).catch((msg) => { + console.log('fail', JSON.stringify(msg)) + // WxHelper.showToast(msg.errMsg || msg.errorMessage || '排行榜获取失败') + }); + } - public static restartMiniProgram() { - if (typeof my != 'undefined') { - game.restart(); - return; + } + public static setRankScore(key: string, score: number, updateType?: number) { + if (cc.sys.platform === cc.sys.ALIPAY_GAME) + AlipayApi.I.setRankScoreData(key, score, updateType); + } + public static async loginWx(isAuthorize: boolean, failFunction?: Function, count?: number, success?: Function): Promise { + count = count != undefined ? count : 3; + let data = await SDKTools.login(isAuthorize); + // console.error(count, 'loginWx', data) + if (data.code == 0) { + success && success(); + return data; + } else if (count >= 0) { + count--; + return await this.loginWx(isAuthorize, failFunction, count); + } else if (failFunction) { + console.warn('--wxlogin--fail', data) + failFunction(); + return null; } - if (!this.isWx) { - return - }; - if (!wx.restartMiniProgram) { - this.showToast("自动重启失败,请手动重启!", 10000); + } + + + + + + public static goToGameCenter(success: Function, fail: Function) { + //每个游戏跳转游戏中心的url 不一样 + 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"; + if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + AlipayApi.I.navigateToMiniProgramByScheme(url, success, fail) } - wx.restartMiniProgram(); } + } \ No newline at end of file diff --git a/sdk/shareTools.ts b/sdk/shareTools.ts index da67952..372bbc6 100644 --- a/sdk/shareTools.ts +++ b/sdk/shareTools.ts @@ -1,20 +1,8 @@ -import { UIManager } from "../../framework/core/view/UIManager"; -import { AudioManager } from "../../framework/mananger/AudioManager"; -import TAMgr from "../../framework/ta/TAMgr"; -import WXSDK from "../../framework/wxsdk/WXSDK"; -import { EventModels, EventPool } from "../const/EventModels"; -import { GameConst } from "../const/GameConst"; -import { EActivitySubTaskType, EWindowExitCode, WindowType } from "../const/types"; -import { mapController } from "../modules/map/MapController"; -import { PayShopManager } from "../modules/server/manager/PayShopManager"; -import { shopController } from "../modules/shop/ShopController"; -import { Utils } from "../utils/Utils"; -import MaskView from "../view/common/MaskView"; +import SDKUtils from "../wxsdk/utils/SDKUtils"; +import WXSDK from "../wxsdk/WXSDK"; import { Analytics } from "./Analytics"; -import { Ge } from "./Ge"; -import { SDKTools } from "./SDKTools"; -import { WxHelper } from "./WxHelper"; - +import SDKShare from "../wxsdk/share/SDKShare"; +import { ShareVideoError } from "../wxsdk/base/SDKConst"; /* * 分享与视频工具类; */ @@ -25,126 +13,92 @@ export class ShareTools { public static onShowAd: boolean = false; public static isTest: boolean = false; - - // private static getAdCount() { - // try { - // let adCount = SDKTools.getParamsString("ad_count", '10,10'); - // let arr = adCount.split(',').map(Number); - // if (SDKTools.isnew) { - // return +arr[0]; - // } else { - // return +arr[1]; - // } - // } catch (error) { - // return 10; - // } - // } /** * 验证分享:可处理成功、失败 * @param shareKey * @param params params.fail 有就不处理,没有自动处理 * @param opts 目前支持4个key 1,title自定义分享标题 2,img_url自定义分享图片 3,share_type(不走后台配置写死走视频or分享。1分享2视频3无视频则分享)4,closeSimulate是否关闭模拟分享 */ - static async share(shareKey: string, params?: { success?: Function, fail?: Function, context?: any }, opts?: any) { - const type = this.getShareType(shareKey); - // 免广告卡、体验卡 - if ((type == 2 && (!opts || opts.share_type != 1)) || (opts && opts.share_type == 2)) { - if (PayShopManager.I.isExperienceOrNoAd()) { - Analytics.I.dot("video_no_ad", { form: shareKey }); - params && params.success && params.success(); - return; - } else { - // 非免广告卡、体验卡用户 检查是否买过体验卡 - if (PayShopManager.I.checkShowExperience()) { - if (shopController.buyExperienceTips != Utils.getDayTime(0)) { - shopController.buyExperienceTips = Utils.getDayTime(0);; - UIManager.instance.showWindow2(WindowType.ExperienceGiftWindow); - params && params.fail && params.fail(); - return; - } - } - } - } - // 广告卡 - if (((type == 2 && (!opts || opts.share_type != 1)) || (opts && opts.share_type == 2)) && mapController.getPackageItemNum(GameConst.ITEM_ADCARD_ID) > 0) { - const ret = await UIManager.instance.waitWindow2(WindowType.AdCardWindow); - if (ret == EWindowExitCode.Yes) { - Analytics.I.dot("ad_card", { ad_card: shareKey }); - params && params.success && params.success(); - return; - } - } - - if ((typeof wx == 'undefined'&&typeof my == 'undefined') || this.isTest) { + static share(shareKey: string, params?: { success?: Function, fail?: Function, context?: any }, opts?: any) { + if (typeof my === 'undefined' || this.isTest) { params && params.success && params.success(); - // 分享 - const evt = EventPool.get(EventModels.AcitvitySubTaskEvent); - evt.type = EActivitySubTaskType.Share; - evt.centerEmit(); return } - - // // 看广告n次后处理为分享 - // let count = this.getAdCount(); - // let isClear = false; - // // console.log("改为分享前:", settingsController.videoCount, count); - // if (settingsController.videoCount >= count) { - // if (type != 1 || (opts && opts.share_type == 2)) {// 视频 or // 强制视频 - // opts = { - // ...opts, - // share_type: 1,//强制改为分享 - // }; - // isClear = true; - // // console.log("改为分享了"); - // } - // } - - this.onShowAd = true; - AudioManager.I.pauseAll(); - if (!opts || !opts.closeSimulate) { - MaskView.Show() + let time = 1500; + let self = this; + if (SDKUtils.compareVersion(my.env.clientVersion, '10.3.70') < 0) { + Analytics.I.dot('videoFail', { "from": 'versionLow' }); + my.showToast({ + type: 'none', + content: '当前版本不支持视频广告哦,请您升级支付宝版本', + duration: time, + }); + return; } + this.onShowAd = true; + WXSDK.share.share(shareKey.toString(), params, opts).then(async res => { this.onShowAd = false; - // if (isClear) { - // settingsController.videoCount = 0; - // } - if (res.type == 2) { - // 视频 - // settingsController.videoCount++; - Ge.I.adShowEvent("video", shareKey.toString()); - TAMgr.Ins.userAdd({ total_ad_num: 1 }); - } else { - // 分享 - const evt = EventPool.get(EventModels.AcitvitySubTaskEvent); - evt.type = EActivitySubTaskType.Share; - evt.centerEmit(); - TAMgr.Ins.dot('share_source', { from: shareKey }); - } params && params.success && params.success(res); - AudioManager.I.resumeAll(); - MaskView.Hide(); - }).catch(async err => { - AudioManager.I.resumeAll(); - MaskView.Hide(); - this.onShowAd = false; - if (!params || !params.fail) { - if (err && err.msg) { - WxHelper.showToast(err.msg) - } + }).catch(async videoErr => { + console.log(JSON.stringify(videoErr)); + let showShare = !(videoErr.code == ShareVideoError.VideoPlaying.code || videoErr.code == ShareVideoError.VideoQuit.code); + if (showShare && SDKUtils.compareVersion(my.env.clientVersion, '10.1.75') > 0) { + SDKShare.I.share(shareKey, params, opts).then(success => { + params && params.success && params.success(success); + Analytics.I.dot('videoFail', { "from": 'share_success' }); + }).catch(shareErr => { + console.log(`share fail${JSON.stringify(shareErr)}`) + Analytics.I.dot('videoFail', { "from": 'share_fail' }); + self.onShowAd = false; + if (!params || !params.fail) { + if (cc.sys.platform === cc.sys.WECHAT_GAME) { + wx.showToast({ + title: shareErr.msg, + icon: 'none', + duration: time + }) + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + Analytics.I.dot('videoFail', { "from": 'other3_' + shareErr.code }); + my.showToast({ + content: shareErr.msg, + type: 'none', + duration: 1500 + }) + } + } else { + Analytics.I.dot('videoFail', { "from": 'other4_' + shareErr.code }); + params && params.fail && params.fail(shareErr); + } + }) } else { - params && params.fail && params.fail(err); + Analytics.I.dot('videoFail', { "from": 'share_versionLow' }); + this.onShowAd = false; + if (!params || !params.fail) { + if (cc.sys.platform === cc.sys.WECHAT_GAME) { + wx.showToast({ + title: videoErr.msg, + icon: 'none', + duration: time + }) + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + Analytics.I.dot('videoFail', { "from": 'other1_' + videoErr.code }); + my.showToast({ + content: videoErr.msg, + type: 'none', + duration: 1500 + }) + } + } else { + Analytics.I.dot('videoFail', { "from": 'other2_' + videoErr.code }); + params && params.fail && params.fail(videoErr); + } } - }) - } - /** - * 必定视频 不走后台配置 - * @param shareKey - * @param params - */ - static video(shareKey: string, params?: { success?: Function, fail?: Function, context?: any }, opts?: any) { - this.share(shareKey, params, { ...opts, share_type: 2 }); + + + + })//this.buildParams(params) } /** * 纯净分享 不处理回调 @@ -175,11 +129,9 @@ export class ShareTools { } } - /** - * 分享到朋友圈 bate 只支持安卓 - */ - static onShareTimeline(title: string, imageUrl: string, imagePreviewUrl?: string, query?: string) { - WXSDK.share.onShareTimeline(title, imageUrl, imagePreviewUrl, query); - } +} + + +export enum ShareKey { } diff --git a/wxsdk/WXSDK.ts b/wxsdk/WXSDK.ts index 9ca5284..677c878 100644 --- a/wxsdk/WXSDK.ts +++ b/wxsdk/WXSDK.ts @@ -7,10 +7,9 @@ import LogService from "./service/LogService"; import AdService from "./service/AdService"; import OnlineService from "./service/OnlineService"; import WxInterstitial from "./wx/WxInterstitial"; -import { sys } from "cc"; export default class WXSDK { public static get isWx(): boolean { - return typeof wx != "undefined" + return typeof (my) != "undefined" } public static get data(): SdkData { return DataService.I.Data; @@ -37,19 +36,38 @@ export default class WXSDK { public static async init() { - if (this.isWx) { + // if (this.isWx) { + // WxInit.I.init(); + // //视频预加载 启动预加载视频会闪屏 + // // setTimeout(() => { + // // WxInterstitial.initInterstitialAd();//插屏预加载 + // // ShareVideoService.I.preloadVideo(); + // // }, 2000); + // if (this.isWx) { + // setTimeout(() => { + // WxInterstitial.initInterstitialAd();//插屏预加载 + // ShareVideoService.I.preloadVideo(); + // }, 2000); + // } + // } + // DataService.I.updateTodayOnlineTime(); + // await this.game.env(); + // if (this.isWx) { + // ShareVideoService.I.init(); + // } + // return Promise.resolve(); + if (cc.sys.platform === cc.sys.ALIPAY_GAME || cc.sys.platform === cc.sys.WECHAT_GAME) { WxInit.I.init(); - //视频预加载 启动预加载视频会闪屏 - if (typeof wx !='undefined') { + // 视频预加载 启动预加载视频会闪屏 + // if (cc.sys.platform === cc.sys.WECHAT_GAME && typeof qq == 'undefined') { + if (typeof qq == 'undefined') { setTimeout(() => { - // WxInterstitial.initInterstitialAd();//插屏预加载 + WXSDK.ad.initInterstitialAd();//插屏预加载 ShareVideoService.I.preloadVideo(); }, 2000); } - } - DataService.I.updateTodayOnlineTime(); - await this.game.env(); - if (this.isWx) { + DataService.I.updateTodayOnlineTime(); + await this.game.env(); ShareVideoService.I.init(); } return Promise.resolve(); diff --git a/wxsdk/alipay/AlipayApi.ts b/wxsdk/alipay/AlipayApi.ts index 74ce6da..98d3997 100644 --- a/wxsdk/alipay/AlipayApi.ts +++ b/wxsdk/alipay/AlipayApi.ts @@ -9,6 +9,7 @@ import WxSystem from "../wx/WxSystem"; import { SDKApi } from "../http/SDKApi"; export default class AlipayApi { + private _requirementVersion = { rank: '10.5.6' } private getVersionError(version: string): { errMsg: string; errCode: number } { return { errMsg: `支持最低版本:${version}`, errCode: -1 }; } @@ -100,7 +101,7 @@ export default class AlipayApi { * 创建激励视频广告组件 */ createRewardedVideoAd(adUnitId: string) { - // if (!this.canIUse(Version.I.getVRewardedVideoAd())) return null; + if (!this.canIUse(Version.I.getVRewardedVideoAd())) return null; return my.createRewardedAd({ adUnitId: adUnitId, }); @@ -229,14 +230,15 @@ export default class AlipayApi { my.onShareAppMessage = function () { return { title: data.title, - bgImgUrl:'https://wxsdk-cdn.miso-lab.com/moon-island/share/zfbshare.jpeg', // desc: , - scImgUrl: data.imageUrl, + imageUrl: data.imageUrl, success: function (res) { - console.log(res); + // console.log(res); + // callback.success() }, fail: function (e) { - console.log(e); + // console.log(e); + // callback.fail() }, complete: function (e) { @@ -246,10 +248,12 @@ export default class AlipayApi { return my.showSharePanel({ success: () => { + // console.log('showSharePanel aa') callback.success(); }, fail: () => { + // console.log('showSharePanel fail') callback.fail(); }, complete: (e) => { @@ -291,13 +295,30 @@ export default class AlipayApi { }); } + + /** + * 如果是从别的小程序内跳转过来的,关闭的时候需要回到之前的小程序 + */ + navigateBackMiniProgram() { + my.navigateBackMiniProgram({ + extraData: { + + }, + success: (res) => { + console.log(res) + }, + fail: (err) => { + console.log(err) + } + }); + } + navigateToMiniProgram(appId: string, path: string, opts: any = {}) { return new Promise((resolve, reject) => { - wx.navigateToMiniProgram({ + my.navigateToMiniProgram({ appId, path, extraData: opts.extraData || {}, - envVersion: opts.envVersion || 'release', success(res: any) { resolve(res); }, @@ -307,6 +328,64 @@ export default class AlipayApi { }); }); } + // 将 scheme 转换为 my.navigateToMiniProgram 的参数 scheme为外部app打开地址 游戏内需要转 + private schemeToParams(scheme) { + if (!scheme.startsWith('alipays:')) { + return { message: '! 非 alipays: 开头' }; + } + var params = {}; + var parseQuery = (str) => { + return str.replace(/^.*?\?/, '').split('&').map(s => { + var p = s.includes('=') ? s.indexOf('=') : s.length; + return [s.slice(0, p), s.slice(p + 1)].map(decodeURIComponent); + }); + }; + for (var [k, v] of parseQuery(scheme)) { + if (k == 'appId') { + if (v.length != 16) { + return { message: `! 非 16 位 appId '${v}'` }; + } + } else if (k == 'chInfo') { + let tempkey = 'startParam'; + let tempValue = params[tempkey] || {}; + tempValue[k] = v; + params[tempkey] = tempValue; + continue; + } else { + continue; + } + // else if (k == 'page') { + // k = 'path'; + // } else if (k == 'query') { + // var o = {}; + // for (var [x, y] of parseQuery(v)) { + // o[x] = y; + // } + // v = o; + // } else if (k == '') { + // continue; + // } else { + // let extraData = 'extraData'; + // let newV = params[extraData] || {}; + // newV[k] = v; + // v = newV; + // k = extraData; + // } + params[k] = v; + } + return { params }; + } + navigateToMiniProgramByScheme(scheme, success, fail) { + let { params, message } = this.schemeToParams(scheme); + console.log('params--', { ...params }); + if (cc.sys.platform != cc.sys.ALIPAY_GAME) return + if (params) { + my.navigateToMiniProgram({ ...params, success, fail,}); + } else { + fail && fail({ error: -1, errorMessage: `无效的小程序 scheme ${scheme}: ${message}` }); + } + } + /** * login获取code接口 @@ -388,15 +467,15 @@ export default class AlipayApi { */ requestMidasPayment(params: { mode: string; env: number; offerId: string; currencyType: string; platform: string; buyQuantity: number; zoneId: string }): Promise { let { mode, env, offerId, currencyType, platform, buyQuantity, zoneId } = params; - console.warn('====> PCSDK AlipayApi requestMidasPayment 支付参数', { - mode, - env, - offerId, - currencyType, - platform, - buyQuantity, - zoneId - }); + // console.warn('====> PCSDK AlipayApi requestMidasPayment 支付参数', { + // mode, + // env, + // offerId, + // currencyType, + // platform, + // buyQuantity, + // zoneId + // }); return new Promise((resolve, reject) => { wx.requestMidasPayment({ mode, @@ -459,19 +538,117 @@ export default class AlipayApi { action_code, action_finish_channel }; - return SDKApi.incrementGameaction(params).then(() => { - // my.confirm({ - // title: '增加量行为', - // content: `${action_code}`, - // confirmButtonText: ``, - // cancelButtonText: '暂不需要', - // success: (result) => { - // }, - // }); + return SDKApi.aliMission(params).then(() => { resolve(null) }) }) } + //段位 + setRankSegmentData(rankKey: string, segment: number, segmentName: string) { + return new Promise((resolve, reject) => { + if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) + if (!this.canIUse('10.5.6')) return reject(this.getVersionError('10.5.6')); + my.setImRankData({ + rankId: rankKey, + dataType: 1, //1 为枚举类型。用于传段位信息。 + value: segmentName, //该用户得了999999分,dataType为0时,需填入正数的字符串 + priority: segment, //段位权重 + updateType: 0, // 0为覆盖更新,1为破纪录更新。 + success(res) { + console.log(res); + resolve(res); + }, + fail(res) { + console.log('fail->', res); + reject(res) + }, + // complete(res) { + // console.log(res); + // } + }); + }); + } + //排行榜成绩 + setRankScoreData(rankKey: string, score: number, updateType: number = 1) { + + return new Promise((resolve, reject) => { + if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) + if (!this.canIUse(this._requirementVersion.rank)) return reject(this.getVersionError(this._requirementVersion.rank)); + my.setImRankData({ + rankId: rankKey, + dataType: 0, //成绩为数字类型 + value: score.toString(), //该用户得了999999分,dataType为0时,需填入正数的字符串 + priority: 0, //dataType为0时,可不传。 + updateType: updateType, // 0为覆盖更新,1为破纪录更新。 + success(res) { + console.log('add-> success', res); + resolve(res); + }, + fail(res) { + console.log('add fail->', res); + reject(res) + } + // complete(res) { + // console.log(res); + // } + }); + }); + } + + canUseRank() { + return this.canIUse(this._requirementVersion.rank) + } + /** + * + * @param rankKey 排行榜唯一ID,唯一标识游戏内的排行榜。 + * @param scorePrefix 排行榜成绩值前缀。 + * @param scoreSuffix 排行榜成绩值后缀。 + */ + getRankList(rankKey: string, scorePrefix?: string, scoreSuffix?: string) { + return new Promise((resolve, reject) => { + if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) + if (!this.canIUse(this._requirementVersion.rank)) return reject(this.getVersionError(this._requirementVersion.rank)); + my.getImRankList({ + rankId: rankKey, + // headImg: '', // 排行榜头部 + scorePrefix: scorePrefix, // 成绩值前缀 + scoreSuffix: scoreSuffix, // 成绩值后缀 + success(res) { + // console.log(res); + resolve(res); + }, + fail(res) { + console.log('getImRankList fail->', JSON.stringify(res)); + reject(res) + }, + // complete(res) { + // console.log(res); + // } + }); + }) + } + + //玩一玩小程序是否已加首咨询 + isAddHomePage(): Promise { + return new Promise((resolve, reject) => { + if (window['my'] == undefined) return reject(false); + let uid = DataService.I.UserId; + let token = DataService.I.Token; + let openid = DataService.I.OpenId; + let params = { + uid, + token, + openid, + }; + SDKApi.isAddHomePage(params).then((data) => { + console.log('--->设首结果', data) + //Y:已添加首页,N:未添加首页 + return resolve(data?.data.consult_result == 'Y') + }).catch(() => { + return reject(false); + }) + }) + } private static _instance: AlipayApi; diff --git a/wxsdk/alipay/AlipayBanner.ts b/wxsdk/alipay/AlipayBanner.ts index 30bf26e..c8c91aa 100644 --- a/wxsdk/alipay/AlipayBanner.ts +++ b/wxsdk/alipay/AlipayBanner.ts @@ -1,238 +1,244 @@ -// import SDKUtils from "../utils/SDKUtils"; -// import { BannerError, __LOG__ } from "../base/SDKConst"; -// import LogService from "../service/LogService"; -// import { DOT_AD_STATUS, DOT_AD_TYPE } from "../base/SDKEnum"; -// import WxSystem from "../wx/WxSystem"; -// import AlipayApi from "./AlipayApi"; - - -// /* -// * banner -// */ -// export default class AlipayBanner { -// private static instance: AlipayBanner; -// static get I(): AlipayBanner { -// return this.instance || (this.instance = new AlipayBanner(750, 750)); -// } -// private designWidth: number; -// private bannerWidth: number; -// private bannerHeight: number; -// private bannerScale: number; -// private bannerParams: any; -// private _isErrored: boolean; -// private adUnitId: string; -// private bannerAd: any; -// private resolve: any; -// private reject: any; - -// constructor(designWidth: number, bannerWidth: number) { -// designWidth = designWidth || 750; -// bannerWidth = bannerWidth || 750; - -// this.adUnitId = ''; -// this._isErrored = false; -// this.designWidth = designWidth; -// this.bannerScale = WxSystem.I.winWidth / this.designWidth; -// this.bannerWidth = Math.max(this.bannerScale * bannerWidth, 300); -// this.bannerHeight = WxSystem.I.winHeight / this.bannerScale; -// } - -// get isErrored() { -// return this._isErrored; -// } - -// private queue: Function[] = []; -// private isEnd: boolean = false; - -// create(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { -// // console.log('wxbanner can not') -// if (SDKUtils.compareVersion(my.env.clientVersion, '10.3.66') < 0) return null; -// // if (!WxApi.I.canIUse(Version.I.getVBannerAd())) -// // console.log('wxbanner can', adUnitId) - -// this.bannerParams = opts || {}; -// if (opts && opts.bannerWidth) { -// this.bannerWidth = opts.bannerWidth; -// } -// this.isEnd = true; -// this.bannerParams.type = this.bannerParams.type || 1; -// this.bannerParams.offsetY = -this.bannerParams.offsetY || 0; -// this.bannerParams.adIntervals = this.bannerParams.adIntervals || 120; -// return new Promise((resolve, reject) => { -// this.resolve = resolve; -// this.reject = reject; -// this._isErrored = false; -// this.adUnitId = adUnitId; - -// if (SDKUtils.isEmpty(adUnitId)) { -// AlipayBanner.I.handleQueue(); -// return this.reject({ ...BannerError.BannerInvalid, adUnitId: this.adUnitId }); -// } - -// // 设置样式(hack:修复qq版本) -// this.bannerParams.type === 2 && (this.bannerWidth = WxSystem.I.winWidth); -// let style = { top: 0, left: (WxSystem.I.winWidth - this.bannerWidth) / 2, width: this.bannerWidth }; -// style = { -// ...style, -// top: WxSystem.I.winHeight - 100, -// }; -// // 创建并判断是否存在 -// // if (this.bannerParams.type === 2) -// // this.bannerAd = wx.createGameBanner({ adUnitId, style: { left: style.left, top: this.bannerHeight } }); -// // else -// if (this.bannerAd) { -// if (!opts || (opts && !opts.isOff)) { -// this.show(false); -// } -// return -// } -// this.bannerAd = AlipayApi.I.createBannerAd(adUnitId, style); -// LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.request) -// if (!this.bannerAd) { -// AlipayBanner.I.handleQueue(); -// return this.reject({ ...BannerError.BannerNotOpen, adUnitId: this.adUnitId }); -// } -// this.bannerAd.onLoad(this.onLoad); -// this.bannerAd.onError(this.onError); -// //支付宝无这个方法!!! -// // this.bannerAd.onResize(this.onResize); -// if (!opts || (opts && !opts.isOff)) { -// this.show(false); -// } -// }); -// } - -// /** -// * -// * @param bol -// */ -// show(bol: boolean = true): boolean { -// if (AlipayBanner.I.isEnd && bol) { -// AlipayBanner.I.queue.push(AlipayBanner.I.show.bind(AlipayBanner.I)) -// return -// } -// AlipayBanner.I.isEnd = true -// if (this.bannerAd) { -// if (this.bannerAd.style.realHeight) -// this.bannerAd.style.top = WxSystem.I.winHeight - this.bannerAd.style.realHeight + this.bannerParams.offsetY; -// if (this.bannerParams.type === 2) { -// if (this.bannerAd.style.width) -// this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerAd.style.width) / 2; -// else -// this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerWidth) / 2; -// } else -// this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerWidth) / 2; - -// LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.show) -// this.bannerAd.show().catch((err: any) => this.handleShowError(err)); -// __LOG__ && console.error('wxBanner - show: ' + this.adUnitId, this.bannerAd.style); -// AlipayBanner.I.handleQueue() -// return true; -// } -// AlipayBanner.I.handleQueue() -// return false; -// } - -// hide() { -// let that = AlipayBanner.I; -// if (that.isEnd) { -// that.queue.push(that.hide.bind(that)) -// return -// } -// that.isEnd = true -// if (this.bannerAd) { -// this.bannerAd.style.left = -9999; -// this.bannerAd.hide(); -// LogService.I.adStat('banner', that.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.interrupt) -// __LOG__ && console.error('wxBanner - hide: ' + this.adUnitId); -// } -// that.handleQueue() -// } - -// toggle(isshow: boolean) { -// isshow ? this.show() : this.hide(); -// } - -// destory() { -// if (this.bannerAd) { -// this.bannerAd.style.left = -9999; -// this.bannerAd.destroy(); -// this.bannerAd = null; -// LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.interrupt) -// __LOG__ && console.error('wxBanner - destory: ' + this.adUnitId); -// } -// } - -// private onLoad() { -// let that = AlipayBanner.I; -// let bannerAd = that.bannerAd; -// if (!bannerAd) return; -// // Platform.IsQQ && that.show(); -// __LOG__ && console.error('wxBanner - onLoad: ' + that.adUnitId); -// if (bannerAd.style.realHeight) -// bannerAd.style.top = WxSystem.I.winHeight - bannerAd.style.realHeight + that.bannerParams.offsetY; -// that.unbind(); -// that.handleQueue(); -// that.resolve && that.resolve({ -// adUnitId: that.adUnitId, -// scale: that.bannerScale, -// width: bannerAd.style.realWidth / that.bannerScale, -// height: bannerAd.style.realHeight / that.bannerScale -// }); -// } - -// private onError(err: any, ...params) { -// __LOG__ && console.error('wxBanner - onError', err, JSON.stringify(err), params); -// let that = AlipayBanner.I; -// !that._isErrored && that.handleError(err, { ...BannerError.BannerFail, adUnitId: that.adUnitId }); -// } - -// private onResize() { -// let that = AlipayBanner.I; -// let bannerAd = that.bannerAd; -// if (!bannerAd) return; -// bannerAd.style.top = WxSystem.I.winHeight - bannerAd.style.realHeight + that.bannerParams.offsetY; -// bannerAd.style.left = (WxSystem.I.winWidth - bannerAd.style.realWidth) / 2; -// } - -// private handleShowError(ret: { errCode: number; errMsg: string }) { -// __LOG__ && console.error('wxBanner - handleShowError', ret); -// let that = AlipayBanner.I; -// let { errCode, errMsg } = ret; -// !that.isErrored && that.handleError(ret, { code: errCode, msg: errMsg }); -// } - -// private handleError(ret: any, err: any) { -// let that = AlipayBanner.I; -// that.unbind(); -// that._isErrored = true; -// that.bannerAd = null; -// that.handleQueue() -// LogService.I.adStat('banner', that.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.fail) -// that.reject && that.reject({ ...err, adUnitId: that.adUnitId }); -// __LOG__ && console.error('wxBanner - onError: ' + that.adUnitId, ret, err); -// } - -// private unbind() { -// if (this.bannerAd) { -// // this.bannerAd.offLoad(this.onLoad); -// // this.bannerAd.offError(this.onError); -// // this.bannerAd.offResize(this.onResize); -// } -// } - -// /** -// * 处队列 -// */ -// handleQueue() { -// let that = AlipayBanner.I; -// if (that.queue.length > 0) { -// that.isEnd = false; -// let fn = that.queue.shift(); -// fn(); -// } else { -// that.isEnd = false; -// } -// } -// } \ No newline at end of file +import SDKUtils from "../utils/SDKUtils"; +import { BannerError, __LOG__ } from "../base/SDKConst"; +import LogService from "../service/LogService"; +import { DOT_AD_STATUS, DOT_AD_TYPE } from "../base/SDKEnum"; +import WxSystem from "../wx/WxSystem"; +import AlipayApi from "./AlipayApi"; + + +/* +* banner +*/ +export default class AlipayBanner { + private static instance: AlipayBanner; + static get I(): AlipayBanner { + return this.instance || (this.instance = new AlipayBanner(750, 750)); + } + private designWidth: number; + private bannerWidth: number; + private bannerHeight: number; + private bannerScale: number; + private bannerParams: any; + private _isErrored: boolean; + private adUnitId: string; + private bannerAd: any; + private resolve: any; + private reject: any; + private _currentVisible: boolean = false; + constructor(designWidth: number, bannerWidth: number) { + designWidth = designWidth || 750; + bannerWidth = bannerWidth || 750; + + this.adUnitId = ''; + this._isErrored = false; + this.designWidth = designWidth; + this.bannerScale = WxSystem.I.winWidth / this.designWidth; + this.bannerWidth = Math.max(this.bannerScale * bannerWidth, 300); + this.bannerHeight = WxSystem.I.winHeight / this.bannerScale; + } + + get isErrored() { + return this._isErrored; + } + + private queue: Function[] = []; + private isEnd: boolean = false; + + create(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { + // console.log('wxbanner can not') + if (SDKUtils.compareVersion(my.env.clientVersion, '10.3.66') < 0) return null; + // if (!WxApi.I.canIUse(Version.I.getVBannerAd())) + // console.log('wxbanner can', adUnitId) + + this.bannerParams = opts || {}; + if (opts && opts.bannerWidth) { + this.bannerWidth = opts.bannerWidth; + } + this.isEnd = true; + this.bannerParams.type = this.bannerParams.type || 1; + this.bannerParams.offsetY = -this.bannerParams.offsetY || 0; + this.bannerParams.adIntervals = this.bannerParams.adIntervals || 120; + return new Promise((resolve, reject) => { + this.resolve = resolve; + this.reject = reject; + this._isErrored = false; + this.adUnitId = adUnitId; + + if (SDKUtils.isEmpty(adUnitId)) { + AlipayBanner.I.handleQueue(); + return this.reject({ ...BannerError.BannerInvalid, adUnitId: this.adUnitId }); + } + + // 设置样式(hack:修复qq版本) + this.bannerParams.type === 2 && (this.bannerWidth = WxSystem.I.winWidth); + let style = { top: 0, left: (WxSystem.I.winWidth - this.bannerWidth) / 2, width: this.bannerWidth }; + style = { + ...style, + top: WxSystem.I.winHeight - 100, + }; + // 创建并判断是否存在 + // if (this.bannerParams.type === 2) + // this.bannerAd = wx.createGameBanner({ adUnitId, style: { left: style.left, top: this.bannerHeight } }); + // else + if (this.bannerAd) { + if (!opts || (opts && !opts.isOff)) { + this.show(false); + } + return + } + this.bannerAd = AlipayApi.I.createBannerAd(adUnitId, style); + console.log('create new BannerAd') + LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.request) + if (!this.bannerAd) { + AlipayBanner.I.handleQueue(); + return this.reject({ ...BannerError.BannerNotOpen, adUnitId: this.adUnitId }); + } + this.bannerAd.onLoad(this.onLoad); + this.bannerAd.onError(this.onError); + //支付宝无这个方法!!! + // this.bannerAd.onResize(this.onResize); + if (!opts || (opts && !opts.isOff)) { + this.show(false); + } + }); + } + + /** + * + * @param bol + */ + show(bol: boolean = true): boolean { + if (AlipayBanner.I.isEnd && bol) { + AlipayBanner.I.queue.push(AlipayBanner.I.show.bind(AlipayBanner.I)) + return + } + AlipayBanner.I.isEnd = true + if (this.bannerAd && !this._currentVisible) { + if (this.bannerAd.style.realHeight) + this.bannerAd.style.top = WxSystem.I.winHeight - this.bannerAd.style.realHeight + this.bannerParams.offsetY; + if (this.bannerParams.type === 2) { + if (this.bannerAd.style.width) + this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerAd.style.width) / 2; + else + this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerWidth) / 2; + } else + this.bannerAd.style.left = (WxSystem.I.winWidth - this.bannerWidth) / 2; + + LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.show) + this._currentVisible = true; + this.bannerAd.show().catch((err: any) => this.handleShowError(err)); + __LOG__ && console.error('wxBanner - show: ' + this.adUnitId, this.bannerAd.style); + AlipayBanner.I.handleQueue() + return true; + } + AlipayBanner.I.handleQueue() + return false; + } + + hide() { + + let that = AlipayBanner.I; + if (that.isEnd) { + that.queue.push(that.hide.bind(that)) + return + } + that.isEnd = true + if (this.bannerAd) { + this.bannerAd.style.left = -9999; + this.bannerAd.hide(); + this._currentVisible = false; + LogService.I.adStat('banner', that.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.interrupt) + __LOG__ && console.error('wxBanner - hide: ' + this.adUnitId); + } + that.handleQueue() + } + + toggle(isshow: boolean) { + isshow ? this.show() : this.hide(); + } + + destory() { + if (this.bannerAd) { + this.bannerAd.style.left = -9999; + this.bannerAd?.destroy(); + this.bannerAd = null; + LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.interrupt) + __LOG__ && console.error('wxBanner - destory: ' + this.adUnitId); + } + } + + private onLoad() { + let that = AlipayBanner.I; + let bannerAd = that.bannerAd; + if (!bannerAd) return; + // Platform.IsQQ && that.show(); + __LOG__ && console.error('wxBanner - onLoad: ' + that.adUnitId); + if (bannerAd.style.realHeight) + bannerAd.style.top = WxSystem.I.winHeight - bannerAd.style.realHeight + that.bannerParams.offsetY; + that.unbind(); + that.handleQueue(); + that.resolve && that.resolve({ + adUnitId: that.adUnitId, + scale: that.bannerScale, + width: bannerAd.style.realWidth / that.bannerScale, + height: bannerAd.style.realHeight / that.bannerScale + }); + } + + private onError(err: any, ...params) { + __LOG__ && console.error('wxBanner - onError', err, JSON.stringify(err), params); + let that = AlipayBanner.I; + !that._isErrored && that.handleError(err, { ...BannerError.BannerFail, adUnitId: that.adUnitId }); + } + + private onResize() { + let that = AlipayBanner.I; + let bannerAd = that.bannerAd; + if (!bannerAd) return; + bannerAd.style.top = WxSystem.I.winHeight - bannerAd.style.realHeight + that.bannerParams.offsetY; + bannerAd.style.left = (WxSystem.I.winWidth - bannerAd.style.realWidth) / 2; + } + + private handleShowError(ret: { errCode: number; errMsg: string }) { + this._currentVisible = false; + __LOG__ && console.error('wxBanner - handleShowError', ret); + let that = AlipayBanner.I; + let { errCode, errMsg } = ret; + !that.isErrored && that.handleError(ret, { code: errCode, msg: errMsg }); + } + + private handleError(ret: any, err: any) { + let that = AlipayBanner.I; + that.unbind(); + that._isErrored = true; + that.bannerAd?.destroy(); + that.bannerAd = null; + that.handleQueue() + LogService.I.adStat('banner', that.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.fail) + that.reject && that.reject({ ...err, adUnitId: that.adUnitId }); + __LOG__ && console.error('wxBanner - onError: ' + that.adUnitId, ret, err); + } + + private unbind() { + if (this.bannerAd) { + // this.bannerAd.offLoad(this.onLoad); + // this.bannerAd.offError(this.onError); + // this.bannerAd.offResize(this.onResize); + } + } + + /** + * 处队列 + */ + handleQueue() { + let that = AlipayBanner.I; + if (that.queue.length > 0) { + that.isEnd = false; + let fn = that.queue.shift(); + fn(); + } else { + that.isEnd = false; + } + } +} \ No newline at end of file diff --git a/wxsdk/alipay/AlipayInterstitial.ts b/wxsdk/alipay/AlipayInterstitial.ts index 5027a98..6a89090 100644 --- a/wxsdk/alipay/AlipayInterstitial.ts +++ b/wxsdk/alipay/AlipayInterstitial.ts @@ -1,68 +1,68 @@ -// import { GAMEDATA } from "../base/SDKConst"; -// import { DOT_AD_STATUS, DOT_AD_TYPE } from "../base/SDKEnum"; -// import LogService from "../service/LogService"; -// import AlipayApi from "./AlipayApi"; +import { GAMEDATA } from "../base/SDKConst"; +import { DOT_AD_STATUS, DOT_AD_TYPE } from "../base/SDKEnum"; +import LogService from "../service/LogService"; +import AlipayApi from "./AlipayApi"; -// export default class AlipayInterstitial { -// /** 插屏广告ID */ -// private static interstitialAdId: string = GAMEDATA.interstitialAdId; -// /** 插屏广告实例 */ -// public static interstitialAd: any; -// /** 插屏广告是否加载完成 */ -// private static interstitialSuccell: boolean = false; -// /** 初始化插屏广告 */ -// public static initInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { -// this.interstitialAdId = adUnitId; -// this.createInterstitial(); -// } +export default class AlipayInterstitial { + /** 插屏广告ID */ + private static interstitialAdId: string = GAMEDATA.interstitialAdId; + /** 插屏广告实例 */ + public static interstitialAd: any; + /** 插屏广告是否加载完成 */ + private static interstitialSuccell: boolean = false; + /** 初始化插屏广告 */ + public static initInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { + this.interstitialAdId = adUnitId; + this.createInterstitial(); + } -// /** 显示插屏广告 */ -// public static showInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { -// return new Promise(async (resolve, reject) => { -// this.interstitialAdId = adUnitId; -// if (!this.interstitialSuccell) { -// this.createInterstitial(true, resolve); -// return; -// } -// this.interstitialAd.show().then(suc => { -// resolve && resolve({ code: 0, msg: "展示成功!" }); -// LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.show) -// }).catch((err) => { -// LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) -// resolve && resolve({ code: err.errCode, msg: err.errMsg }); -// }) -// }) -// } + /** 显示插屏广告 */ + public static showInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { + return new Promise(async (resolve, reject) => { + this.interstitialAdId = adUnitId; + if (!this.interstitialSuccell) { + this.createInterstitial(true, resolve); + return; + } + this.interstitialAd.show().then(suc => { + resolve && resolve({ code: 0, msg: "展示成功!" }); + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.show) + }).catch((err) => { + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) + resolve && resolve({ code: err.errCode, msg: err.errMsg }); + }) + }) + } -// /** 创建插屏广告 */ -// private static createInterstitial(isShow: boolean = false, resolve?) { -// LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.request) -// this.interstitialAd = AlipayApi.I.createInterstitialAd(this.interstitialAdId); -// this.interstitialAd.onLoad(async () => { -// AlipayInterstitial.interstitialSuccell = true; -// LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.rt) -// if (isShow) { -// this.interstitialAd.show().then(suc => { -// resolve && resolve({ code: 0, msg: "展示成功!" }); -// LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.show) -// }).catch((err) => { -// AlipayInterstitial.interstitialSuccell = false; -// LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) -// resolve && resolve({ code: err.errCode, msg: err.errMsg }); -// }) -// } -// }) -// this.interstitialAd.onError(err => { -// LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) -// AlipayInterstitial.interstitialSuccell = false; -// resolve && resolve({ code: err.errCode, msg: err.errMsg }); -// }) + /** 创建插屏广告 */ + private static createInterstitial(isShow: boolean = false, resolve?) { + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.request) + this.interstitialAd = AlipayApi.I.createInterstitialAd(this.interstitialAdId); + this.interstitialAd.onLoad(async () => { + AlipayInterstitial.interstitialSuccell = true; + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.rt) + if (isShow) { + this.interstitialAd.show().then(suc => { + resolve && resolve({ code: 0, msg: "展示成功!" }); + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.show) + }).catch((err) => { + AlipayInterstitial.interstitialSuccell = false; + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) + resolve && resolve({ code: err.errCode, msg: err.errMsg }); + }) + } + }) + this.interstitialAd.onError(err => { + LogService.I.adStat('InterstitialAd', this.interstitialAdId, DOT_AD_TYPE.interstitial, DOT_AD_STATUS.fail) + AlipayInterstitial.interstitialSuccell = false; + resolve && resolve({ code: err.errCode, msg: err.errMsg }); + }) -// this.interstitialAd.onClose(call => { -// this.createInterstitial(false); -// }) -// // }).bind(this), 200); + this.interstitialAd.onClose(call => { + this.createInterstitial(false); + }) + // }).bind(this), 200); -// } -// } \ No newline at end of file + } +} \ No newline at end of file diff --git a/wxsdk/alipay/zfbPay.ts b/wxsdk/alipay/zfbPay.ts deleted file mode 100644 index e9e4e87..0000000 --- a/wxsdk/alipay/zfbPay.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { WxHelper } from '../../../game/sdk/WxHelper'; -import { GAMEDATA } from '../base/SDKConst'; -import { EnvCode } from '../base/SDKEnum'; -import { SDKApi } from '../http/SDKApi'; -import DataService from '../service/DataService'; -import WxSystem from '../wx/WxSystem'; - -export default class ZfbPay { - /** - * 发起支付 - */ - pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}): Promise { - return new Promise((resolve, reject) => { - let { Mode, OfferId, ZoneId, CurrencyType, Platform } = GAMEDATA.MidasPay; - // 环境配置,0:米大师正式环境 1:米大师沙箱环境 - let env = DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1; - // 平台类型,android or ios,config.js有配置走配置,否则判断系统id - let platform = DataService.I.Platform; - let pms = { - mode: Mode, - env, - platform, - offerId: OfferId, - currencyType: CurrencyType, - buyQuantity: params.money / 10, - zoneId: ZoneId - }; - let extend = ""; - for (let key in opts) { - extend += (`${key}=${opts[key]}&`) - } - extend = extend.substring(0, extend.length - 1); - extend = encodeURIComponent(extend); - - let payParams = { - ...this.buildParams(), - extend, - orderid: params.orderid, - // payid: params.payid, - goodid: params.goodid, - money: params.money, - platform - }; - SDKApi.zfbOrderReport(payParams).then(res => { - console.log("res:" + JSON.stringify(res)); - console.log("调用函数成功00"); - if (!res.code) { - let { customId, buyQuantity, extraInfo } = res.data; - my.requestGamePayment({ - customId, - buyQuantity, - extraInfo, - success(res) { - console.log("调用函数成功"); - resolve({ code: 0, msg: '支付成功!' }) - }, - fail(err) { - console.log("调用函数失败"); - if (err && err.error) { - if ("" + err.error == '15215') { - my.alert({ - title: '您好,基于国家新闻出版署《关于防止未成年人沉迷网络游戏的通知》的规定,支付宝限制未成年人游戏充值哦', - }); - } else if ("" + err.error == '15204') { - my.alert({ - title: '非常抱歉,充值功能暂不可用,请稍后再试', - }); - } - } - resolve({ code: err.errCode, msg: '支付失败' }); - }, - complete(res) { - try { - console.log(JSON.stringify(res)); - } catch (error) { - - } - console.log(res) - console.log("调用完成"); - }, - }) - } else { - console.log("调用函数成功222"); - reject(res); - } - }) - }); - } - - private async handlePaySuccess(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts: any, resolve: any, reject: any, t = 1000) { - let extend = ""; - for (let key in opts) { - extend += (`${key}=${opts[key]}&`) - } - extend = extend.substring(0, extend.length - 1); - extend = encodeURIComponent(extend); - let params = { - ...this.buildParams(), - extend, - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, - orderid: data.orderid, - payid: data.payid, goodid: data.goodid, - type: 1, - money: data.money, - platform: data.platform - }; - var that = this; - SDKApi.zfbOrderReport(params) - .then(res => { - if (!res.code) { - resolve(res); - } else { - t = Math.min(t * 2, 60000) - setTimeout(() => { - that.handlePaySuccess(data, opts, resolve, reject, t) - }, t); - } - }) - } - - private handlePayError(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts, err: any, reject: any) { - console.log("支付失败", JSON.stringify(err)); - let type = 2; - if (err.errCode + '' == '1') { - type = 3; - } - let extend = ""; - for (let key in opts) { - extend += (`${key}=${opts[key]}&`) - } - extend = extend.substring(0, extend.length - 1); - extend = encodeURIComponent(extend); - let params = { - ...this.buildParams(), - extend, - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, - orderid: data.orderid, - payid: data.payid, goodid: data.goodid, - type, - money: data.money, - platform: data.platform - }; - SDKApi.zfbOrderReport(params) - reject(err); - } - - /** - * 构建支付公用参数 - */ - private buildParams() { - let gameid = GAMEDATA.game_id; - let channel = DataService.I.ChannelId; - let openid = DataService.I.OpenId; - let brand = WxSystem.I.brand; - let model = WxSystem.I.model; - let version = WxSystem.I.version; - let system = WxSystem.I.system; - let sdkversion = WxSystem.I.SDKVersion; - let scene = DataService.I.Scene + ''; - let uid = DataService.I.UserId; - let token = DataService.I.Token; - let env = DataService.I.EnvEnum === 1 ? 'pre' : 'prod'; - return { - gameid, - openid, - channel, - brand, - model, - version, - system, - sdkversion, - scene, - uid, - token, - env - }; - } - - private static _instance: ZfbPay; - static get I(): ZfbPay { - return this._instance || (this._instance = new ZfbPay); - } -} \ No newline at end of file diff --git a/wxsdk/base/SDKBaseData.ts b/wxsdk/base/SDKBaseData.ts index 33a4336..f40a00b 100644 --- a/wxsdk/base/SDKBaseData.ts +++ b/wxsdk/base/SDKBaseData.ts @@ -1,3 +1,3 @@ export default class SDKBaseData{ - public static SimulateShareTime:number = 1000; + public static SimulateShareTime:number = 3000; } \ No newline at end of file diff --git a/wxsdk/base/SDKConst.ts b/wxsdk/base/SDKConst.ts index c372009..6d73b25 100644 --- a/wxsdk/base/SDKConst.ts +++ b/wxsdk/base/SDKConst.ts @@ -1,39 +1,35 @@ // 游戏配置数据 只需要改动这里的配置信息 +// 2021003184609526 export const GAMEDATA = { - game_id: '10110',//游戏id + game_id: '10150',//游戏id isDebug: false, - channel_id: '10110',//渠道id 暂时和游戏id一致 + channel_id: '10150',//渠道id 暂时和游戏id一致 version: '1.0.0', //版本号 中台控制正式还是测试服,尽量保持和小游戏版本一致 - appkey: '48ef655c48f53f1e75f2108cf65d394e',//中台appkey - interstitialAdId: 'adunit-4bd19de3c351233e',//插屏ID - bannerId: 'adunit-6145b17777e308a8',//banner - customId: 'adunit-193590de82ede6a4',//原生模板单个 - videoAd: 'adunit-59404ef14e6c32ed',//初始化视频广告id + appkey: '761bdbb773c59e545ac729adec818ddc',//中台appkey + interstitialAdId: 'ad_tiny_2021004125691158_202311162200070802',//插屏ID + bannerId: 'ad_tiny_2021004125691158_202311162200070801',//banner + customId: '',//原生模板单个 + videoAd: 'ad_tiny_2021004125691158_202311162200070775',//初始化视频广告id shareMessageToFriend: { // 暂时只支持一个场景值 scene: 0, //定向分享场景值1-50 配>0的会初始化 sharekey: 'shareMessageToFriendScene',//定向分享对应后台的分享key share_id: 26,//定向分享对应后台的分享key }, - default_share: { //默认分享数据在拉取不到中台分享数据的时候用 - content: '惊喜世界合不停',//分享标题 *找运营提供 - icon: 'https://cdn-wxsdk.miso-lab.com/7d/da1ed3fb6073ddd43f156f98c625e3.jpg',//分享图链接 *找运营提供 - id: '9999',//默认id 写死9999 - key: 'default',//默认分享key 写死default - title: '默认',//无需修改 - typ: 1,//分享类型 写死1 - videoid: '',//默认的视频广告id 填空就行 + default_share: { + content: '还记得童年的泡泡龙吗?一起来怀旧吧~ 这个可以不?', + icon: 'https://cdn-wxsdk.miso-lab.com/f0/5653094b6b7826c8afd813d12735e3.jpg', + id: '9999', + key: 'default', + title: '默认', + typ: 1, + videoid: '' }, - MidasPay: { // 米大师虚拟支付配置 *找运营提供 - OfferId: "1450051274", // 在米大师申请的应用id *找运营提供 - ZoneId: "1", // 分区ID,默认:1 - Mode: "game", // 默认:game - CurrencyType: "CNY", // 默认:CNY - Platform: '' // 申请接入时的平台 - } + subscribeIds: ['yB-vq0DvOhazzDbvS1UzttLMIQ50Z_i0n8st6yEZYkw', '4al8p3UBb3xqn7TYN1J5wYtKrCbFc2MYESAv1vWi-C0'], //, 'cMo71MjAFzGM2MEpRw2p8T5jJaEhXJUfiIjoOB5oO70'], + versionContent: '1、开启每日幸运转盘活动\r\n2、针对部分玩家出现的卡顿问题进行修复' } // sdk版本 -export const SDKVersion = 'v1.0.15'; +export const SDKVersion = 'v1.0.8'; // 是否打印 export const __LOG__ = false; // 是否mock @@ -41,6 +37,8 @@ export var sdkEnv = { isDebug: false }; + + //游戏基础信息 export const VersionHost = 'https://wxsdk-ver.d3games.com/version'; @@ -86,7 +84,6 @@ export const HostKeys = { client_log: 'logstores/client_log/track', //客户端日志 consume: 'logstores/consume/track', //资源上报 daystay: 'logstores/daystay/track', //300s停留上报 - loading: 'logstores/loading/track', //loading上报 //登录 Login: 'api/login', //登录 @@ -102,27 +99,29 @@ export const HostKeys = { rankAdd: 'api/rank/add', //排行榜添加分数 517废弃 rankList: 'api/rank/list', //世界排行榜 517废弃 totalrankAdd: 'game/totalrank/add', //排行榜添加分数 - totalrankList: 'game/totalrank/list', //世界排行榜 + totalrankList: 'game/totalrank/list', //世界排行榜 + sendsubscribe: 'api/subscribe/event', //订阅 adList: 'api/adplan/list', //广告计划列表 + notice: 'game/notice/info', //公告 behavior: 'api/douyin/behavior', //抖音投放关键行为 attribute: 'api/member/attribute/set', //修改用户属性 - wxencrypted: 'api/wx/encrypted', checkmsg: 'api/wx/checkmsg', //检测文本 updateNickname: 'api/member/update/nickname',//更改用户昵称头像 + wxencrypted: 'api/wx/encrypted', //订单 - orderReport: 'api/order/v2/mimas/new', //wx订单信息上报 - orderQuery: 'api/order/query', //订单信息查询 - preorder: 'api/order/v2/preorder', //获取支付方式 - bytedanceOrderReport: 'api/order/v2/bytedance', //字节订单信息上报 - qqOrderReport: 'api/order/v2/qq', //qq订单信息上报 - zfbOrderReport:'api/order/v2/zfb/add', //支付宝小游戏订单上报 + orderReport: 'api/order/v2/mimas/new', //订单信息上报 + orderQuery: 'api/order/query', //订单信息查询 + preorder: 'api/order/v2/preorder', //获取支付方式 // goodslist: 'api/v2/goodslist', //商品列表 - //支付宝 - AlipayIncrementGameaction: 'api/ali/action/submit' ,//玩一玩:增量游戏行为完成上报 + aliMission: 'api/ali/action/submit',//阿里玩一玩增量任务 + alipayIntergralBuy: 'api/ali/point/pay',//支付宝会员积分购买 + alipayIntergralAuth: 'api/ali/point/auth',//支付宝会员积分授权 + alipayIntergralQuery: 'api/ali/point/query',//支付宝会员积分查询 + isAddHomePage: 'api/ali/homepage/consult',//玩一玩小程序是否已加首咨询 }; // 本地存储keys diff --git a/wxsdk/base/SDKDefault.d.ts b/wxsdk/base/SDKDefault.d.ts new file mode 100644 index 0000000..59a7e90 --- /dev/null +++ b/wxsdk/base/SDKDefault.d.ts @@ -0,0 +1,230 @@ + +/** 返回参数类型 */ +interface IResult { + /** 错误码 */ + code?: number; + /** 错误信息 */ + msg?: string; + /** 返回数据 */ + data?: T; + /** 服务器时间 */ + servertime?: number; +} + +/** 微信api 返回用户信息 */ +interface WxUserInfo { + /** 用户昵称 */ + nickName: string; + /** 用户头像图片的 URL。URL 最后一个数值代表正方形头像大小 + * (有 0、46、64、96、132 数值可选,0 代表 640x640 的正方形头像,46 表示 46x46 的正方形头像, + * 剩余数值以此类推。默认132),用户没有头像时该项为空。若用户更换头像,原有头像 URL 将失效。 */ + avatarUrl: string; + /** 用户性别 gender的合法值(0未知,1男性,2女性) */ + gender: number; + /** 用户所在国家 */ + country: string; + /** 用户所在省份 */ + province: string; + /** 用户所在城市 */ + city: string; + /** 显示 country,province,city 所用的语言(en英文,zh_CN简体中文,zh_TW繁体中文) */ + language: string; +} + +/** 显示模态对话框参数类型 */ +interface ShowModalType { + /** 提示的标题 */ + title: string; + /** 提示的内容 */ + content: string; + /** 是否显示取消按钮 */ + showCancel?: boolean; + /** 取消按钮的文字,最多 4 个字符 */ + cancelText?: string; + /** 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串 */ + cancelColor?: string; + /** 确认按钮的文字,最多 4 个字符 */ + confirmText?: string; + /** 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串 */ + confirmColor?: string; + /** 接口调用成功的回调函数 */ + success?: (res: { confirm: boolean, cancel: boolean }) => void; + /** 接口调用失败的回调函数 */ + fail?: () => void; + /** 接口调用结束的回调函数(调用成功、失败都会执行) */ + complete?: () => void; +} +/** + * 排行榜数据 + */ +interface IRankData { + fraction: number, // 对应type传入的分数、数量或者其他 + headurl: string, //头像 + nickname: string,//昵称 + uid: number//用户id + rankData: any //扩展参数 +} + +interface _NetworkTypeSuccessObject { + networkType: string; // wifi/2g/3g/4g/unknown(Android 下不常见的网络类型)/none(无网络) +} +interface _StyleObject { + left?: number; + + top?: number; + + width?: number; + + height?: number; +} +interface _StyleGameObject { + left?: number; + top?: number; +} + +interface _BannerAdObject { + adUnitId: string; + adIntervals?: number; + style: _StyleObject; +} +interface _FeedbackButtonObject { + /** + * 按钮的类型 + */ + type: string; + + /** + * 按钮上的文本,仅当 type 为 text 时有效 + */ + text?: string; + + /** + * 按钮的背景图片,仅当 type 为 image 时有效 + */ + image?: string; + + /** + * 按钮的样式 + */ + style: _ButtonStyle; +} + +interface _UserInfoButton { + type: string; + + text: string; + + image: string; + + style: _ButtonStyle; + + show: Function; + + hide: Function; + + destroy: Function; + + onTap: (callback: Function) => void; + + offTap: (callback: Function) => void; +} + +interface _ShareAppMessageObject { + /** + * 是否使用带 shareTicket 的转发详情 + */ + withShareTicket?: boolean; + /** + * 发标题,不传则默认使用当前小游戏的昵称。 + */ + title?: string; + + /** + * 转发显示图片的链接,可以是网络图片路径或本地图片文件路径或相对代码包根目录的图片文件路径。显示图片长宽比是 5: 4 + */ + imageUrl?: string; + + /** + * 查询字符串,必须是 key1 = val1 & key2=val2 的格式。从这条转发消息进入后,可通过 wx.getLaunchOptionSync() 或 wx.onShow() 获取启动参数中的 query。 + */ + query?: string; + + /** + * 审核通过的图片 ID,详见 使用审核通过的转发图片 + */ + imageUrlId?: string; + + /** + * 10.10后废弃 + */ + success?: (ret?: any) => void; + + /** + * 接口调用失败的回调函数 + */ + fail?: (err?: any) => void; + + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + */ + complete?: () => void; + + /** + * 接口取消的回调 + */ + cancel?: () => void; +} +interface _UpdateShareMenuObject { + /** + * 是否使用带 shareTicket 的转发 + */ + withShareTicket?: boolean; + + /** + * 接口调用成功的回调函数 + */ + success?: () => void; + + /** + * 接口调用失败的回调函数 + */ + fail?: () => void; + + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + */ + complete?: () => void; + + /** + * 接口取消的回调 + */ + cancel?: () => void; +} +interface _getShareInfoSuccessObject { + /** + * 错误信息 + */ + errMsg: string; + + /** + * 包括敏感数据在内的完整转发信息的加密数据,详细见[加密数据解密算法](./signature.md#加密数据解密算法) + */ + encryptedData: string; + + /** + * 加密算法的初始向量,详细见[加密数据解密算法](./signature.md#加密数据解密算法) + */ + iv: string; +} + + +interface IGameList { + id: number,//唯一id + appid: string,//微信appid + path: string, //携带参数 + icon: string, //游戏icon + game: string //游戏名称 + adtyp: string,//类型 + animation: string,//骨骼 + highlight: string,//是否高亮 +} diff --git a/wxsdk/base/SDKDefault.ts b/wxsdk/base/SDKDefault.ts deleted file mode 100644 index 59a7e90..0000000 --- a/wxsdk/base/SDKDefault.ts +++ /dev/null @@ -1,230 +0,0 @@ - -/** 返回参数类型 */ -interface IResult { - /** 错误码 */ - code?: number; - /** 错误信息 */ - msg?: string; - /** 返回数据 */ - data?: T; - /** 服务器时间 */ - servertime?: number; -} - -/** 微信api 返回用户信息 */ -interface WxUserInfo { - /** 用户昵称 */ - nickName: string; - /** 用户头像图片的 URL。URL 最后一个数值代表正方形头像大小 - * (有 0、46、64、96、132 数值可选,0 代表 640x640 的正方形头像,46 表示 46x46 的正方形头像, - * 剩余数值以此类推。默认132),用户没有头像时该项为空。若用户更换头像,原有头像 URL 将失效。 */ - avatarUrl: string; - /** 用户性别 gender的合法值(0未知,1男性,2女性) */ - gender: number; - /** 用户所在国家 */ - country: string; - /** 用户所在省份 */ - province: string; - /** 用户所在城市 */ - city: string; - /** 显示 country,province,city 所用的语言(en英文,zh_CN简体中文,zh_TW繁体中文) */ - language: string; -} - -/** 显示模态对话框参数类型 */ -interface ShowModalType { - /** 提示的标题 */ - title: string; - /** 提示的内容 */ - content: string; - /** 是否显示取消按钮 */ - showCancel?: boolean; - /** 取消按钮的文字,最多 4 个字符 */ - cancelText?: string; - /** 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串 */ - cancelColor?: string; - /** 确认按钮的文字,最多 4 个字符 */ - confirmText?: string; - /** 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串 */ - confirmColor?: string; - /** 接口调用成功的回调函数 */ - success?: (res: { confirm: boolean, cancel: boolean }) => void; - /** 接口调用失败的回调函数 */ - fail?: () => void; - /** 接口调用结束的回调函数(调用成功、失败都会执行) */ - complete?: () => void; -} -/** - * 排行榜数据 - */ -interface IRankData { - fraction: number, // 对应type传入的分数、数量或者其他 - headurl: string, //头像 - nickname: string,//昵称 - uid: number//用户id - rankData: any //扩展参数 -} - -interface _NetworkTypeSuccessObject { - networkType: string; // wifi/2g/3g/4g/unknown(Android 下不常见的网络类型)/none(无网络) -} -interface _StyleObject { - left?: number; - - top?: number; - - width?: number; - - height?: number; -} -interface _StyleGameObject { - left?: number; - top?: number; -} - -interface _BannerAdObject { - adUnitId: string; - adIntervals?: number; - style: _StyleObject; -} -interface _FeedbackButtonObject { - /** - * 按钮的类型 - */ - type: string; - - /** - * 按钮上的文本,仅当 type 为 text 时有效 - */ - text?: string; - - /** - * 按钮的背景图片,仅当 type 为 image 时有效 - */ - image?: string; - - /** - * 按钮的样式 - */ - style: _ButtonStyle; -} - -interface _UserInfoButton { - type: string; - - text: string; - - image: string; - - style: _ButtonStyle; - - show: Function; - - hide: Function; - - destroy: Function; - - onTap: (callback: Function) => void; - - offTap: (callback: Function) => void; -} - -interface _ShareAppMessageObject { - /** - * 是否使用带 shareTicket 的转发详情 - */ - withShareTicket?: boolean; - /** - * 发标题,不传则默认使用当前小游戏的昵称。 - */ - title?: string; - - /** - * 转发显示图片的链接,可以是网络图片路径或本地图片文件路径或相对代码包根目录的图片文件路径。显示图片长宽比是 5: 4 - */ - imageUrl?: string; - - /** - * 查询字符串,必须是 key1 = val1 & key2=val2 的格式。从这条转发消息进入后,可通过 wx.getLaunchOptionSync() 或 wx.onShow() 获取启动参数中的 query。 - */ - query?: string; - - /** - * 审核通过的图片 ID,详见 使用审核通过的转发图片 - */ - imageUrlId?: string; - - /** - * 10.10后废弃 - */ - success?: (ret?: any) => void; - - /** - * 接口调用失败的回调函数 - */ - fail?: (err?: any) => void; - - /** - * 接口调用结束的回调函数(调用成功、失败都会执行) - */ - complete?: () => void; - - /** - * 接口取消的回调 - */ - cancel?: () => void; -} -interface _UpdateShareMenuObject { - /** - * 是否使用带 shareTicket 的转发 - */ - withShareTicket?: boolean; - - /** - * 接口调用成功的回调函数 - */ - success?: () => void; - - /** - * 接口调用失败的回调函数 - */ - fail?: () => void; - - /** - * 接口调用结束的回调函数(调用成功、失败都会执行) - */ - complete?: () => void; - - /** - * 接口取消的回调 - */ - cancel?: () => void; -} -interface _getShareInfoSuccessObject { - /** - * 错误信息 - */ - errMsg: string; - - /** - * 包括敏感数据在内的完整转发信息的加密数据,详细见[加密数据解密算法](./signature.md#加密数据解密算法) - */ - encryptedData: string; - - /** - * 加密算法的初始向量,详细见[加密数据解密算法](./signature.md#加密数据解密算法) - */ - iv: string; -} - - -interface IGameList { - id: number,//唯一id - appid: string,//微信appid - path: string, //携带参数 - icon: string, //游戏icon - game: string //游戏名称 - adtyp: string,//类型 - animation: string,//骨骼 - highlight: string,//是否高亮 -} diff --git a/wxsdk/base/wx.d.ts b/wxsdk/base/wx.d.ts index 1b142d5..1205cb8 100644 --- a/wxsdk/base/wx.d.ts +++ b/wxsdk/base/wx.d.ts @@ -1,4 +1,4 @@ declare const wx; declare const qq; -declare const my; \ No newline at end of file +declare const my; diff --git a/wxsdk/douyin/DouyinInterstitial.ts b/wxsdk/douyin/DouyinInterstitial.ts deleted file mode 100644 index 307ac1b..0000000 --- a/wxsdk/douyin/DouyinInterstitial.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { GAMEDATA } from "../base/SDKConst"; - -export default class DouyinInterstitial { - /** 插屏广告ID */ - private static interstitialAdId: string = GAMEDATA.interstitialAdId; - /** 插屏广告实例 */ - public static interstitialAd: any; - /** 插屏广告是否加载完成 */ - private static interstitialSuccell: boolean = false; - /** 初始化插屏广告 */ - public static initInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { - // this.interstitialAdId = adUnitId; - // this.createInterstitial(); - } - - private static canReTry = false; - /** 显示插屏广告 */ - public static showInterstitialAd(adUnitId: string = GAMEDATA.interstitialAdId) { - const interstitiaAd = tt.createInterstitialAd({ adUnitId: this.interstitialAdId }); - this.canReTry = true; - let onLoadHandle = ()=> { - console.log("插屏广告onload成功") - interstitiaAd.show().then(() => { - console.log("插屏广告展示成功"); - }); - } - interstitiaAd.onLoad(onLoadHandle); //创建会自动load - - let onErrorHandle = (err)=>{ - // 这里要等待一定时间后,或者等待下次需要展示的时候,参考频控,尝试一次,或者几次,不能一直尝试。 - if (this.canReTry) { - this.canReTry = false; - interstitiaAd.load(); //如果需要,这里等待一定时间后,或者等待下次需要展示的时候,再次 load->onLoad-> show。 - } else { - tt.showToast({ - title: "暂无广告", - icon: "none", - }); - } - } - interstitiaAd.onError(onErrorHandle); // 自动load 的失败会走到这里 - } -} \ No newline at end of file diff --git a/wxsdk/douyin/DouyinPay.ts b/wxsdk/douyin/DouyinPay.ts deleted file mode 100644 index 8026a93..0000000 --- a/wxsdk/douyin/DouyinPay.ts +++ /dev/null @@ -1,175 +0,0 @@ -import { GAMEDATA } from '../base/SDKConst'; -import { EnvCode } from '../base/SDKEnum'; -import { SDKApi } from '../http/SDKApi'; -import DataService from '../service/DataService'; -import WxSystem from '../wx/WxSystem'; - -export default class DouyinPay { - /** - * 发起支付 - */ - pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}): Promise { - return new Promise((resolve, reject) => { - let { Mode, OfferId, ZoneId, CurrencyType, Platform } = GAMEDATA.MidasPay; - // 环境配置,0:米大师正式环境 1:米大师沙箱环境 - let env = DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1; - // 平台类型,android or ios,config.js有配置走配置,否则判断系统id - let platform = DataService.I.Platform; - let pms = { - mode: Mode, - env, - platform, - offerId: OfferId, - currencyType: CurrencyType, - buyQuantity: params.money / 10, - zoneId: ZoneId - }; - let extend = ""; - for (let key in opts) { - extend += (`${key}=${opts[key]}&`) - } - extend = extend.substring(0, extend.length - 1); - extend = encodeURIComponent(extend); - - let payParams = { - ...this.buildParams(), - extend, - orderid: params.orderid, - // payid: params.payid, - goodid: params.goodid, - money: params.money, - platform - }; - console.log("payParams", payParams); - SDKApi.bytedanceOrderReport(payParams).then(res => { - console.log("res", res); - if (!res.code) { - let { mode, env, currencyType, platform, buyQuantity, zoneId, customId, extraInfo } = res.data; - tt.requestGamePayment({ - mode, // 支付类型 - env, //支付环境 - currencyType, // 币种:目前仅为 "CNY" - platform, // 申请接入时的平台:目前仅为"android" - buyQuantity, // 购买数量,必须满足:金币数量*金币单价 = 限定价格等级(详见金币限定等级) - zoneId, - customId,//开发者自定义唯一订单号。如不填,支付结果回调将不包含此字段,将导致游戏开发者无法发放游戏道具, 基础库版本低于1.55.0没有此字段 - extraInfo,//extraInfo要转成字符串 - success(res) { - // console.log("调用函数成功", res); - resolve({ code: 0, msg: '支付成功!' }) - }, - fail(err) { - // console.log("调用函数失败", res); - resolve({ code: err.errCode, msg: '支付失败' }); - }, - complete(res) { - // console.log("调用完成", res); - }, - }) - // tt.requestGamePayment(pms) - // .then(() => this.handlePaySuccess({ ...params, platform }, opts, resolve, reject)) - // .catch(err => this.handlePayError({ ...params, platform }, opts, err, reject)); - } else { - reject(res); - } - }) - }); - } - - private async handlePaySuccess(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts: any, resolve: any, reject: any, t = 1000) { - // let code = await WxApi.I.login(); - - let extend = ""; - for (let key in opts) { - extend += (`${key}=${opts[key]}&`) - } - extend = extend.substring(0, extend.length - 1); - extend = encodeURIComponent(extend); - let params = { - ...this.buildParams(), - extend, - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, - orderid: data.orderid, - payid: data.payid, goodid: data.goodid, - type: 1, - money: data.money, - platform: data.platform - }; - var that = this; - SDKApi.bytedanceOrderReport(params) - .then(res => { - if (!res.code) { - resolve(res); - } else { - t = Math.min(t * 2, 60000) - // console.error("上报失败,重新上报", t) - setTimeout(() => { - that.handlePaySuccess(data, opts, resolve, reject, t) - }, t); - } - }) - } - - private handlePayError(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts, err: any, reject: any) { - console.log("支付失败", JSON.stringify(err)); - let type = 2; - if (err.errCode + '' == '1') { - type = 3; - } - let extend = ""; - for (let key in opts) { - extend += (`${key}=${opts[key]}&`) - } - extend = extend.substring(0, extend.length - 1); - extend = encodeURIComponent(extend); - let params = { - ...this.buildParams(), - extend, - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, - orderid: data.orderid, - payid: data.payid, goodid: data.goodid, - type, - money: data.money, - platform: data.platform - }; - SDKApi.bytedanceOrderReport(params) - reject(err); - } - - /** - * 构建支付公用参数 - */ - private buildParams() { - let gameid = GAMEDATA.game_id; - let channel = DataService.I.ChannelId; - let openid = DataService.I.OpenId; - let brand = WxSystem.I.brand; - let model = WxSystem.I.model; - let version = WxSystem.I.version; - let system = WxSystem.I.system; - let sdkversion = WxSystem.I.SDKVersion; - let scene = DataService.I.Scene + ''; - let uid = DataService.I.UserId; - let token = DataService.I.Token; - let env = DataService.I.EnvEnum === 1 ? 'pre' : 'prod'; - return { - gameid, - openid, - channel, - brand, - model, - version, - system, - sdkversion, - scene, - uid, - token, - env - }; - } - - private static _instance: DouyinPay; - static get I(): DouyinPay { - return this._instance || (this._instance = new DouyinPay); - } -} \ No newline at end of file diff --git a/wxsdk/http/SDKApi.ts b/wxsdk/http/SDKApi.ts index 0899e7b..1c7aecf 100644 --- a/wxsdk/http/SDKApi.ts +++ b/wxsdk/http/SDKApi.ts @@ -9,10 +9,13 @@ export class SDKApi { //GameApi public static ShareList = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.ShareList, ...args); + public static notice = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.notice, ...args); public static getConfig = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.getConfig, ...args); //订阅 public static subscribe = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.subscribe, ...args); + public static sendsubscribe = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.sendsubscribe, ...args); + // public static saveData = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.saveData, ...args); public static getData = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.getData, ...args); @@ -30,18 +33,17 @@ export class SDKApi { public static behavior = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.behavior, ...args); //修改用户属性 public static attribute = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.attribute, ...args); - // 解密关系链互动数据 - public static wxencrypted = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.wxencrypted, ...args); // 文本检测 public static checkmsg = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.checkmsg, ...args); - // - public static updateNickname = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.updateNickname, ...args); //LoginApi public static Login = (...args) => SDKHttp.httpPost(DataService.I.LoginApi, HostKeys.Login, ...args); public static reftoken = (...args) => SDKHttp.httpPost(DataService.I.LoginApi, HostKeys.Reftoken, ...args); public static weakLogin = (...args) => SDKHttp.httpPost(DataService.I.LoginApi, HostKeys.weakLogin, ...args); + public static updateNickname = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.updateNickname, ...args); + // 解密关系链互动数据 + public static wxencrypted = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.wxencrypted, ...args); //DotApi @@ -72,28 +74,31 @@ export class SDKApi { public static client_log = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.client_log, ...args); public static consume = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.consume, ...args); - + public static daystay = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.daystay, ...args); - - public static loading = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.loading, ...args); // OrderApi public static pay = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderReport, ...args); - public static bytedanceOrderReport = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.bytedanceOrderReport, ...args); - public static qqOrderReport = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.qqOrderReport, ...args); public static orderQuery = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderQuery, ...args); public static preorder = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.preorder, ...args); - public static zfbOrderReport = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.zfbOrderReport, ...args); - + public static goodslist = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.goodslist, ...args); - //支付宝 - /** - * 玩一玩增量行为 - * @param args - * @returns - */ - public static incrementGameaction = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.AlipayIncrementGameaction, ...args); + + //阿里增量任务 + public static aliMission = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.aliMission, ...args); + + //支付宝会员授权查询 + public static alipayIntergralAuth = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.alipayIntergralAuth, ...args); + + //支付宝积分查询 + public static alipayIntergralQuery = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.alipayIntergralQuery, ...args); + //支付宝积分购买 + public static alipayIntergralBuy = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.alipayIntergralBuy, ...args); + + + //玩一玩小程序是否已加首咨询 + public static isAddHomePage = (...args) => SDKHttp.httpPost(DataService.I.GameApi, HostKeys.isAddHomePage, ...args); } diff --git a/wxsdk/http/SDKHttp.ts b/wxsdk/http/SDKHttp.ts index f7fad29..b0899c9 100644 --- a/wxsdk/http/SDKHttp.ts +++ b/wxsdk/http/SDKHttp.ts @@ -21,7 +21,7 @@ export default class SDKHttp { if (data && typeof data === "object") { data = JSON.stringify(data); } - // console.error("sign", url, JSON.stringify(data)) + console.error("sign"+ url+JSON.stringify(data)) data = data || ""; if (method == "GET" && data != "") { data = JSON.parse(data); @@ -38,7 +38,7 @@ export default class SDKHttp { if (xhr.readyState == 4) { if (xhr.status >= 200 && xhr.status < 400) { let responseText: any = xhr.responseText; - // cc.log("responseText", responseText) + cc.log("responseText"+ responseText) try { responseText = JSON.parse(responseText); // cc.log("responseText22", responseText) @@ -54,31 +54,39 @@ export default class SDKHttp { return; } } else { - console.error(xhr.status, '网络请求失败!'); - resolve({ code: -2 }); + // console.error(xhr.status, '网络请求失败!'); + resolve({ code: -5 }); } } }; xhr.ontimeout = function (info): void { // cc.error("info1", info) - resolve({ msg: `请求超时!`, code: -3 }); + resolve({ msg: `请求超时!`, code: -2 }); } xhr.onerror = function (info): void { // cc.error("info2", info) - resolve({ msg: `请求失败!`, code: -4 }); + resolve({ msg: `请求失败!`, code: -3 }); } xhr.onabort = function (info): void { // cc.error("info3", info) - resolve({ msg: `请求失败!`, code: -5 }); + resolve({ msg: `请求失败!`, code: -4 }); } xhr.open(method, url, true); if (method == "POST") { xhr.setRequestHeader("Content-Type", "application/json;charset=utf-8")//application/x-www-form-urlencoded + // if (cc.sys.os === 'Android') { + // cc.error("http__uid", AppSdkData.I.uid); + // xhr.setRequestHeader('Uuid', `${AppSdkData.I.uid}`); + // } else { + // xhr.setRequestHeader('Uuid', `909`); + // } + } - xhr.timeout = 10000; + xhr.timeout = 3000; + // console.log(data) xhr.send(data); }); } diff --git a/wxsdk/platform/wx/WxStorage.ts.meta b/wxsdk/platform/wx/WxStorage.ts.meta index e2f3294..e76a04b 100644 --- a/wxsdk/platform/wx/WxStorage.ts.meta +++ b/wxsdk/platform/wx/WxStorage.ts.meta @@ -1,9 +1,9 @@ { - "ver": "4.0.23", - "importer": "typescript", - "imported": true, + "ver": "1.0.8", "uuid": "6013014c-7aa3-4eb4-b818-583d937a9f05", - "files": [], - "subMetas": {}, - "userData": {} -} + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/wxsdk/qq/QQPay.ts b/wxsdk/qq/QQPay.ts deleted file mode 100644 index 0067e1b..0000000 --- a/wxsdk/qq/QQPay.ts +++ /dev/null @@ -1,165 +0,0 @@ -import { GAMEDATA } from '../base/SDKConst'; -import { EnvCode } from '../base/SDKEnum'; -import { SDKApi } from '../http/SDKApi'; -import DataService from '../service/DataService'; -import WxSystem from '../wx/WxSystem'; - -export default class QQPay { - /** - * 发起支付 - */ - pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}): Promise { - return new Promise((resolve, reject) => { - let { Mode, OfferId, ZoneId, CurrencyType, Platform } = GAMEDATA.MidasPay; - // 环境配置,0:米大师正式环境 1:米大师沙箱环境 - let env = DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1; - // 平台类型,android or ios,config.js有配置走配置,否则判断系统id - let platform = DataService.I.Platform; - let pms = { - mode: Mode, - env, - platform, - offerId: OfferId, - currencyType: CurrencyType, - buyQuantity: params.money / 10, - zoneId: ZoneId - }; - let extend = ""; - for (let key in opts) { - extend += (`${key}=${opts[key]}&`) - } - extend = extend.substring(0, extend.length - 1); - extend = encodeURIComponent(extend); - - let payParams = { - ...this.buildParams(), - extend, - orderid: params.orderid, - // payid: params.payid, - goodid: params.goodid, - money: params.money, - platform - }; - console.log("payParams", payParams); - SDKApi.qqOrderReport(payParams).then(res => { - console.log("res", res); - if (!res.code) { - let { prepayId,starCurrency,setEnv } = res.data; - qq.requestMidasPayment({ - prepayId, - starCurrency, - setEnv, - success(res) { - // console.log("调用函数成功", res); - resolve({ code: 0, msg: '支付成功!' }) - }, - fail(err) { - // console.log("调用函数失败", res); - resolve({ code: err.errCode, msg: '支付失败' }); - }, - complete(res) { - console.log("调用完成", res); - }, - }) - } else { - reject(res); - } - }) - }); - } - - private async handlePaySuccess(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts: any, resolve: any, reject: any, t = 1000) { - let extend = ""; - for (let key in opts) { - extend += (`${key}=${opts[key]}&`) - } - extend = extend.substring(0, extend.length - 1); - extend = encodeURIComponent(extend); - let params = { - ...this.buildParams(), - extend, - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, - orderid: data.orderid, - payid: data.payid, goodid: data.goodid, - type: 1, - money: data.money, - platform: data.platform - }; - var that = this; - SDKApi.qqOrderReport(params) - .then(res => { - if (!res.code) { - resolve(res); - } else { - t = Math.min(t * 2, 60000) - // console.error("上报失败,重新上报", t) - setTimeout(() => { - that.handlePaySuccess(data, opts, resolve, reject, t) - }, t); - } - }) - } - - private handlePayError(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts, err: any, reject: any) { - console.log("支付失败", JSON.stringify(err)); - let type = 2; - if (err.errCode + '' == '1') { - type = 3; - } - let extend = ""; - for (let key in opts) { - extend += (`${key}=${opts[key]}&`) - } - extend = extend.substring(0, extend.length - 1); - extend = encodeURIComponent(extend); - let params = { - ...this.buildParams(), - extend, - midasenv: DataService.I.EnvEnum === EnvCode.Prod ? 0 : 1, - orderid: data.orderid, - payid: data.payid, goodid: data.goodid, - type, - money: data.money, - platform: data.platform - }; - SDKApi.qqOrderReport(params) - reject(err); - } - - /** - * 构建支付公用参数 - */ - private buildParams() { - let gameid = GAMEDATA.game_id; - let channel = DataService.I.ChannelId; - let openid = DataService.I.OpenId; - let brand = WxSystem.I.brand; - let model = WxSystem.I.model; - let version = WxSystem.I.version; - let system = WxSystem.I.system; - let sdkversion = WxSystem.I.SDKVersion; - let scene = DataService.I.Scene + ''; - let uid = DataService.I.UserId; - let token = DataService.I.Token; - let env = DataService.I.EnvEnum === 1 ? 'pre' : 'prod'; - return { - gameid, - openid, - channel, - brand, - model, - version, - system, - sdkversion, - scene, - uid, - token, - env - }; - } - - private static _instance: QQPay; - static get I(): QQPay { - return this._instance || (this._instance = new QQPay); - } -} \ No newline at end of file diff --git a/wxsdk/service/AdService.ts b/wxsdk/service/AdService.ts index 362782d..db1f65b 100644 --- a/wxsdk/service/AdService.ts +++ b/wxsdk/service/AdService.ts @@ -4,8 +4,9 @@ import WxCustom from "../wx/WxCustom"; import WxInterstitial from "../wx/WxInterstitial"; import { GAMEDATA } from "../base/SDKConst"; import LogService from "./LogService"; -import DouyinInterstitial from "../douyin/DouyinInterstitial"; -import { sys } from "cc"; +import AlipayInterstitial from "../alipay/AlipayInterstitial"; +import AlipayApi from "../alipay/AlipayApi"; +import AlipayBanner from "../alipay/AlipayBanner"; @@ -17,37 +18,80 @@ export default class AdService { * @param adUnitId * @param opts */ - createBanner(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean,isCreate?:boolean }) { - return WxBanner.I.create(adUnitId, opts); + createBanner(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { + + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { + return null + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + return AlipayBanner.I.create(adUnitId) + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { + return WxBanner.I.create(adUnitId, opts); + } } /** * banner 显示 ps:创建默认显示 */ showBanner() { - WxBanner.I.show() + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { + + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + AlipayBanner.I.show(); + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { + WxBanner.I.show(); + } + } /** * banner 隐藏 */ hideBanner() { - WxBanner.I.hide(); + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { + + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + AlipayBanner.I.hide(); + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { + WxBanner.I.hide(); + } } /** * banner 销毁 */ destoryBanner() { - WxBanner.I.destory(); + + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { + + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + AlipayBanner.I.destory(); + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { + WxBanner.I.destory(); + } } - + /** + * 初始化插屏 + * @param adUnitId + */ + initInterstitialAd(adUnitId?: string) { + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { + // return DouyinInterstitial.initInterstitialAd(adUnitId); + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + AlipayInterstitial.initInterstitialAd(adUnitId) + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { + return WxInterstitial.initInterstitialAd(adUnitId) + } + } /** * 插屏 * @param adUnitId */ createInterstitialAd(adUnitId: string) { - if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME) { - return DouyinInterstitial.showInterstitialAd(adUnitId); - } else { + console.log('~~~~~~~~~~~插屏'); + // return WxInterstitial.showInterstitialAd(adUnitId) + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { + // return DouyinInterstitial.initInterstitialAd(adUnitId); + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + AlipayInterstitial.showInterstitialAd(adUnitId) + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { return WxInterstitial.showInterstitialAd(adUnitId) } } @@ -86,7 +130,13 @@ export default class AdService { let { id, appid, path, game } = data; LogService.I.jumps(id, type); if (!path) path = `?channel_id=${GAMEDATA.channel_id}`; - return WxApi.I.navigateToMiniProgram(appid, path, opts) + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + return AlipayApi.I.navigateToMiniProgram(appid, path, opts) + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { + return WxApi.I.navigateToMiniProgram(appid, path, opts) + } + } diff --git a/wxsdk/service/DataService.ts b/wxsdk/service/DataService.ts index 8e22dab..d3dc476 100644 --- a/wxsdk/service/DataService.ts +++ b/wxsdk/service/DataService.ts @@ -16,25 +16,13 @@ export default class DataService { this._data = new SdkData; // 0点数据变动 let expiration = +((this.nextDay() - Date.now()) / 1000).toFixed(0); - setTimeout(this.resetData.bind(this), expiration * 1000); - if (typeof wx != 'undefined' || typeof my != 'undefined') { - wx.onShow(this.onShow.bind(this)); - wx.onHide(this.onHide.bind(this)); - } - } + setTimeout(this.resetData, expiration * 1000); - onShow() { - // console.log("dataOnshow"); - this.updateTodayOnlineTime(); - } - onHide() { - // console.log("dataOnhide"); - clearInterval(this.timeInterval); } - private resetData() { + private resetData(){ this.setPtm(0);//更新当天是否300s - this.setLogindays(this.logindays + 1);// 更新登录天数 + this.setLogindays(this.logindays+1);// 更新登录天数 this.setIsnew(0);//更新新老用户 } @@ -49,6 +37,7 @@ export default class DataService { }; } + get Data(): SdkData { return this._data; } @@ -527,13 +516,6 @@ export default class DataService { return this; } - // public addOnlineTime(t) { - // let expiration = +((this.nextDay() - Date.now()) / 1000).toFixed(0); - // let time = StorageUtils.I.get("pcsdk_today_online_time") || 0; - // time += t; - // StorageUtils.I.set("pcsdk_today_online_time", time, expiration) - // } - private timeInterval public updateTodayOnlineTime() { let dot = StorageUtils.I.get("pcsdk_today_online_time_300") || 0; @@ -547,16 +529,14 @@ export default class DataService { return; } else { this.setPtm(0) - this.timeInterval = setInterval(this.stayFun.bind(this), 1000); + this.timeInterval = setInterval(this.stayFun.bind(this), 5000); } } - - private stayFun() { let expiration = +((this.nextDay() - Date.now()) / 1000).toFixed(0); let time = StorageUtils.I.get("pcsdk_today_online_time") || 0; - time += 1; - StorageUtils.I.set("pcsdk_today_online_time", time, expiration); + time += 5; + StorageUtils.I.set("pcsdk_today_online_time", time, expiration) let dot = StorageUtils.I.get("pcsdk_today_online_time_300") || 0; if (dot === 1) { this.setPtm(1) @@ -567,7 +547,7 @@ export default class DataService { }, expiration * 1000); return; } - // console.log("newUserTime", time, dot) + // console.log("newUserTime", newUserTime, newUserDot) if (time >= 300 && dot == 0) { StorageUtils.I.set("pcsdk_today_online_time_300", 1, expiration); this.setPtm(1) diff --git a/wxsdk/service/GameService.ts b/wxsdk/service/GameService.ts index bf7535d..e75773f 100644 --- a/wxsdk/service/GameService.ts +++ b/wxsdk/service/GameService.ts @@ -1,14 +1,10 @@ -import { sys } from "cc"; -import { GAMEDATA, SDKVersion, __LOG__ } from "../base/SDKConst"; -import DouyinPay from "../douyin/DouyinPay"; +import DataService from "./DataService"; import { SDKApi } from "../http/SDKApi"; -import QQPay from "../qq/QQPay"; -import WxApi from "../wx/WxApi"; +import { GAMEDATA, SDKVersion, __LOG__ } from "../base/SDKConst"; import WxLogin from "../wx/WxLogin"; +import WxApi from "../wx/WxApi"; import WxPay from "../wx/WxPay"; import WxSystem from "../wx/WxSystem"; -import DataService from "./DataService"; -import ZfbPay from "../alipay/zfbPay"; export default class GameService { @@ -39,6 +35,7 @@ export default class GameService { return WxLogin.I.login(isAuthorize); } + saveData(key: string, content: string) { return SDKApi.saveData({ key, content, uid: DataService.I.UserId, token: DataService.I.Token }); } @@ -65,12 +62,38 @@ export default class GameService { adList(adtyp) { return SDKApi.adList({ adtyp, uid: DataService.I.UserId, token: DataService.I.Token }) } - - wxencrypted(iv, encryptedData) { - return SDKApi.wxencrypted({ iv, encryptedData, openid: DataService.I.OpenId, token: DataService.I.Token, uid: DataService.I.UserId }) + getGameNotice() { + return SDKApi.notice(); } + // subScribe(tmplIds: Array, ids: Array): Promise { + // return new Promise((resolve, reject) => { + // WxApi.I.subscribeMessage(tmplIds) + // .then((ret: any) => { + // ret = ret || {}; + // let acceptKeys = tmplIds.filter((idKey: string) => ret[idKey] && ret[idKey] === 'accept'); + // if (!acceptKeys.length) { + // reject({ errCode: 0, errMsg: '点击取消订阅' }); + // } else { + // let uid = +DataService.I.UserId; + // let token = DataService.I.Token + ''; + // let openid = DataService.I.OpenId + ''; + // let id = ids//JSON.stringify() + // SDKApi.subscribe({ + // uid, + // token, + // openid, + // status: 1, + // id, + // }) + // resolve({ code: 0, msg: '订阅成功!' }) + // } + + // }) + // .catch(err => reject(err)); + // }); + // } subScribe(tmplIds: Array, success: Function, fail: Function): Promise { return new Promise((resolve, reject) => { WxApi.I.subscribeMessage(tmplIds) @@ -79,15 +102,55 @@ export default class GameService { let acceptKeys = tmplIds.filter((idKey: string) => ret[idKey] && ret[idKey] === 'accept'); if (!acceptKeys.length) { fail() - resolve({ errCode: 0, errMsg: '点击取消订阅' }); + reject({ errCode: 0, errMsg: '点击取消订阅' }); + } else { + // let uid = +DataService.I.UserId; + // let token = DataService.I.Token + ''; + // let openid = DataService.I.OpenId + ''; + // UserManager.I.issubscribe = true; success(acceptKeys) console.log('订阅成功', ret, acceptKeys) + // SDKApi.subscribe({ + // uid, + // token, + // openid, + // status: 1, + // message: encodeURI(message), + // sendtime: sendtime, + // time: time, + // }) resolve(ret); } + // GameService.I.subScribe(acceptKeys) + // .then(() => { + // resolve(ret); + // DebugUtils.I.dynamic('====> PCSDK subScribe订阅消息成功', ret); + // }) + // .catch((err) => reject(err || { errCode: 0, errMsg: 'GameApi subScribe请求错误' })); + }) - .catch(err => resolve(err)); + .catch(err => reject(err)); }); + // return WxApi.I.subscribeMessage(template_ids); + } + + async sendSubScribe(tmplIds: Array, message: string, sendtime: number, time: number = 0) { + let uid = +DataService.I.UserId; + let token = DataService.I.Token + ''; + let openid = DataService.I.OpenId + ''; + + let back = await SDKApi.sendsubscribe({ + uid, + token, + openid, + status: 1, + message: encodeURIComponent(message), + sendtime: Math.floor(sendtime), + time: time, + temid: tmplIds[0] + }) + return back; } /** @@ -97,18 +160,7 @@ export default class GameService { * @returns */ pay(params: { payid: string, goodid: string, money: number; orderid: string }, opts: any = {}) { - if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME) { - return DouyinPay.I.pay(params, opts); - } else { - if (typeof my != 'undefined') { - return ZfbPay.I.pay(params, opts); - } else if (typeof qq != 'undefined') { - console.log("QQ支付") - return QQPay.I.pay(params, opts); - } else { - return WxPay.I.pay(params, opts); - } - } + return WxPay.I.pay(params, opts); } /** * 订单查询 @@ -136,38 +188,6 @@ export default class GameService { return SDKApi.goodslist(); } - - /** - * 文本检测 - */ - checkmsg(scene: number, content: string, nickname?: string, title?: string, signature?: string) { - let gameid = GAMEDATA.game_id; - let uid = DataService.I.UserId; - let token = DataService.I.Token; - let openid = DataService.I.OpenId; - return SDKApi.checkmsg({ - gameid, - uid, - token, - openid, - scene, content, nickname, title, signature - }) - } - /** - * 更换昵称和头像 - */ - updateNickname(nickname: string, headurl: string) { - let gameid = GAMEDATA.game_id; - let uid = DataService.I.UserId; - let token = DataService.I.Token; - let pkv = SDKVersion; - return SDKApi.updateNickname({ - gameid, uid, token, pkv, - nickname, headurl - }) - } - - /** * 构建登录/弱登录公用参数 */ @@ -217,6 +237,58 @@ export default class GameService { } + //阿里增量任务 + async aliMission(action_code, success: Function, fail: Function) { + let res = await SDKApi.aliMission({ + ...this.buildParamsAli(action_code), + }); + if (res.code) { + fail(res); + } else + success(res); + } + + /** + * { + "uid": 99, + "token": "12313123werwerwerewrw", + "openid": "2088012968344861", + "action_code": "pplwg_game_pass_level_3", + "action_finish_channel": "gamecenter" + } + * 阿里增量任务 + */ + public buildParamsAli(_action_code) { + console.log('阿里增量任务') + if (window['my'] == undefined) return; + let channel = 'other'; + let info = my.getLaunchOptionsSync(); + // console.log('~~~~~~~~~~~~action_finish_channel=', info); + // console.log('~~~~~~~~~~~~action_finish_channel=', info.query); + // console.log('~~~~~~~~~~~~action_finish_channel=', info.query.channel); + if (info.query.channel == undefined) { + channel = 'other'; + } else { + if (info.query.channel.length <= 0 || info.query.channel == null) { + channel = 'other'; + } else { + channel = info.query.channel; + } + } + + let uid = DataService.I.UserId; + let token = DataService.I.Token; + let openid = DataService.I.OpenId; + let action_code = _action_code; + let action_finish_channel = channel + return { + uid, + token, + openid, + action_code, + action_finish_channel + }; + } /** * 构建登录/弱登录公用参数 diff --git a/wxsdk/service/LogService.ts b/wxsdk/service/LogService.ts index e238bb8..5d6be7f 100644 --- a/wxsdk/service/LogService.ts +++ b/wxsdk/service/LogService.ts @@ -199,7 +199,7 @@ export default class LogService { * @param times 时间 * @param perc 失败时的完成进度 (浮点数) */ - async levelEnd(stageid, stagename, pattern, event, times, perc?) { + async levelEnd(stageid, stagename, pattern, event, times, perc?, valence=0) { let fun = () => SDKApi.level({ ...this.buildParams(), stageid, @@ -208,7 +208,8 @@ export default class LogService { event, times, perc, - typ: 3 + typ: 3, + valence }) this.checkLogin(fun); } @@ -458,25 +459,25 @@ export default class LogService { /** * 客户端日志 */ - clientLog(content, level = SDKLogLevel.debug) { + clientLog(content, level = LogLevel.debug) { SDKApi.client_log({ APIVersion: '0.6.0', gameid: GAMEDATA.game_id, cacheUserId: StorageUtils.I.get("userId") || "0", - level: SDKLogLevel[level], + level: LogLevel[level], content }) switch (level) { - case SDKLogLevel.error: + case LogLevel.error: console.error(content); break; - case SDKLogLevel.debug: + case LogLevel.debug: console.log(content); break; - case SDKLogLevel.info: + case LogLevel.info: console.info(content); break; - case SDKLogLevel.warning: + case LogLevel.warning: console.warn(content); break; default: @@ -510,22 +511,6 @@ export default class LogService { }) this.checkLogin(fun); } - /** - * loading上报 - * @param typ 1开始加载、2加载进行中、3加载结束 - * @param stageid 加载id - * @param stagename 加载内容 - * @param event complete:成功 fail:失败 - * @param times 加载消耗时间 单位毫秒 - * @param perc 完成度 - */ - loading(typ: string, stageid: string, stagename: string, event: string, times: string, perc?: number) { - let fun = () => SDKApi.loading({ - ...this.buildParams(), - typ, stageid, stagename, event, times, perc - }) - this.checkLogin(fun); - } /** @@ -586,7 +571,7 @@ export default class LogService { error:更严重的问题,软件没能执行一些功能 critical:一个严重的错误,这表明程序本身可能无法继续运行 */ -export enum SDKLogLevel { +export enum LogLevel { debug, info, warning, diff --git a/wxsdk/service/ShareVideoService.ts b/wxsdk/service/ShareVideoService.ts index 63ea6fe..6dbd66c 100644 --- a/wxsdk/service/ShareVideoService.ts +++ b/wxsdk/service/ShareVideoService.ts @@ -6,7 +6,6 @@ import { __LOG__, GAMEDATA } from "../base/SDKConst"; import { SDKApi } from "../http/SDKApi"; import DataService from "./DataService"; import SDKVideo from "../share/SDKVideo"; -import { sys } from "cc"; export default class ShareVideoService { private forwardKey?: string; @@ -28,28 +27,18 @@ export default class ShareVideoService { this.forward(this.forwardKey); } - private cnt: number = 1 - async initList() { //初始化List + async init() { let data = await SDKApi.ShareList(); - if (data.code) { - console.log('拉取ShareList失败!') - setTimeout(this.initList.bind(this), 200 * this.cnt) - this.cnt++; - return - } - console.log('拉取ShareList成功!') - console.log('拉取ShareList成功!',JSON.stringify(data)); this.setShareVideoData(data); - if (this.forwardKey) this.forward(this.forwardKey); - } - async init() { - this.initList(); + // console.log(JSON.stringify(data)) SDKShare.I.updateShareMenu(true);//打开群分享 - if (sys.platform === sys.Platform.WECHAT_GAME) { - if (GAMEDATA.shareMessageToFriend.scene > 0) { - wx.setMessageToFriendQuery({ shareMessageToFriendScene: GAMEDATA.shareMessageToFriend.scene }) - } + + + if (GAMEDATA.shareMessageToFriend.scene > 0) { + my.setMessageToFriendQuery({ shareMessageToFriendScene: GAMEDATA.shareMessageToFriend.scene }) } + + if (this.forwardKey) this.forward(this.forwardKey); } preload = true; @@ -411,10 +400,6 @@ export default class ShareVideoService { return list[index]; } - onShareTimeline(title?: string, imageUrl?: string, imagePreviewUrl?: string, query?: string) { - return SDKShare.I.onShareTimeline(title, imageUrl, imagePreviewUrl, query); - } - private createQuery(params = {}): string { let q = params["query"]; delete params["query"]; diff --git a/wxsdk/service/entity/SdkData.ts.meta b/wxsdk/service/entity/SdkData.ts.meta index 2f1044d..9e6fe1a 100644 --- a/wxsdk/service/entity/SdkData.ts.meta +++ b/wxsdk/service/entity/SdkData.ts.meta @@ -1,9 +1,9 @@ { - "ver": "4.0.23", - "importer": "typescript", - "imported": true, + "ver": "1.0.8", "uuid": "f09e38ff-4d68-417e-8904-949127e4d321", - "files": [], - "subMetas": {}, - "userData": {} -} + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/wxsdk/service/entity/ShareData.ts.meta b/wxsdk/service/entity/ShareData.ts.meta index 50c2b54..f510aaa 100644 --- a/wxsdk/service/entity/ShareData.ts.meta +++ b/wxsdk/service/entity/ShareData.ts.meta @@ -1,9 +1,9 @@ { - "ver": "4.0.23", - "importer": "typescript", - "imported": true, + "ver": "1.0.8", "uuid": "d9db9b13-470b-456d-95ff-75354ec23ca0", - "files": [], - "subMetas": {}, - "userData": {} -} + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/wxsdk/share/SDKShare.ts b/wxsdk/share/SDKShare.ts index 956baa9..df44f8a 100644 --- a/wxsdk/share/SDKShare.ts +++ b/wxsdk/share/SDKShare.ts @@ -48,18 +48,20 @@ export default class SDKShare { reject(null); } }; + // 是否模拟分享 + this.shareSimulate && !opts.closeSimulate && this.simulate({ ...callbackObj }); if (this.shareSimulate && opts.closeSimulate) { LogService.I.share(shareKey, share_id, DOT_SHARE_TYPE.share) } // 主动拉起转发 - if (typeof my != 'undefined') { + if (cc.sys.platform === cc.sys.ALIPAY_GAME) { //模拟分享支付宝上面会失败 return AlipayApi.I.shareAppMessage(commonObj, callbackObj) + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { + return wx.shareAppMessage(commonObj); } else { - // 是否模拟分享 - this.shareSimulate && !opts.closeSimulate && this.simulate({ ...callbackObj }); - wx.shareAppMessage(commonObj); + return callbackObj.success(); } }); } @@ -69,7 +71,7 @@ export default class SDKShare { */ updateShareMenu(value) { if (typeof wx == 'undefined') return - wx.updateShareMenu({ + my.updateShareMenu({ withShareTicket: value }); } @@ -81,12 +83,10 @@ export default class SDKShare { forward(params: any, opts: any = {}) { let me = this; let { title, imageUrl, query, imageUrlId } = params; - if (typeof my != 'undefined') { + if (cc.sys.platform === cc.sys.ALIPAY_GAME) { my.onShareAppMessage = function () { return { title: title, - scImgUrl: imageUrl, - bgImgUrl: 'https://wxsdk-cdn.miso-lab.com/moon-island/share/zfbshare.jpeg', success: (ret?: any) => { __LOG__ && console.error('WxShare forward success'); opts.success && opts.success.call(opts.context, ret); @@ -100,36 +100,33 @@ export default class SDKShare { } } } - return; + } else { + wx.onShareAppMessage(function () { + let obj = { + title, + imageUrl, + query, + imageUrlId: imageUrlId || '', + success: (ret?: any) => { + __LOG__ && console.error('WxShare forward success'); + opts.success && opts.success.call(opts.context, ret); + }, + fail: (err?: any) => { + __LOG__ && console.error('WxShare forward fail'); + opts.fail && opts.fail.call(opts.context, err); + }, + cancel: () => { + __LOG__ && console.error('WxShare forward cancel', null); + opts.fail && opts.fail.call(opts.context, null); + } + }; + // 模拟分享 + me.shareSimulate && !opts.closeSimulate && me.simulate({ ...obj }); + return obj; + }); + // 显示当前页面的转发按钮 + wx.showShareMenu({}); } - wx.onShareAppMessage(function () { - let obj = { - title, - imageUrl, - query, - imageUrlId: imageUrlId || '', - success: (ret?: any) => { - __LOG__ && console.error('WxShare forward success'); - opts.success && opts.success.call(opts.context, ret); - }, - fail: (err?: any) => { - __LOG__ && console.error('WxShare forward fail'); - opts.fail && opts.fail.call(opts.context, err); - }, - cancel: () => { - __LOG__ && console.error('WxShare forward cancel', null); - opts.fail && opts.fail.call(opts.context, null); - } - }; - // 模拟分享 - me.shareSimulate && !opts.closeSimulate && me.simulate({ ...obj }); - return obj; - }); - // 显示当前页面的转发按钮 "shareAppMessage"表示“发送给朋友”按钮,"shareTimeline"表示“分享到朋友圈”按钮 - wx.showShareMenu({ - withShareTicket: true, - menus: ['shareAppMessage', 'shareTimeline'] - }) } @@ -151,18 +148,4 @@ export default class SDKShare { SimulateShare.I.bind(data); } - onShareTimeline(title?: string, imageUrl?: string, imagePreviewUrl?: string, query?: string) { - if (wx?.onShareTimeline) { - wx.onShareTimeline(() => { - return { - title,//朋友圈标题 - imageUrl, // 朋友圈 小图 - imagePreviewUrl,//朋友圈 预览大图 - query, - } - }) - } - - } - } \ No newline at end of file diff --git a/wxsdk/share/SDKVideo.ts b/wxsdk/share/SDKVideo.ts index 943b86d..ead43b6 100644 --- a/wxsdk/share/SDKVideo.ts +++ b/wxsdk/share/SDKVideo.ts @@ -1,8 +1,6 @@ -import { sys } from "cc"; import { ShareVideoError, __LOG__ } from "../base/SDKConst"; import { DOT_AD_TYPE, DOT_AD_STATUS } from "../base/SDKEnum"; import LogService from "../service/LogService"; -import TAMgr from "../../ta/TAMgr"; import AlipayApi from "../alipay/AlipayApi"; /* @@ -36,6 +34,7 @@ export default class SDKVideo { private isPreload: boolean = false preloadVideo(adUnitId: string) { if (this.preloadVideoAd || this.isPreload) return + // console.log('preloadVideo--') this.isPreload = true; let ad; if (typeof my != 'undefined') { @@ -96,12 +95,9 @@ export default class SDKVideo { return reject({ ...ShareVideoError.VideoInvalid }); LogService.I.adStat(videoKey, this.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.request); - TAMgr.Ins.dot('video', { - ad_key: videoKey, - type: DOT_AD_STATUS.request - }) - let videoAd - let hasVideo + let videoAd; + let hasVideo; + if (this.preloadVideoAd) { __LOG__ && console.log("使用预加载视频") hasVideo = true @@ -167,7 +163,7 @@ export default class SDKVideo { } } - this.preloadVideo(adUnitId); + // this.preloadVideo(adUnitId); __LOG__ && console.warn('====> PCSDK WxVideo 请求视频adUnitId', adUnitId); }); } @@ -183,11 +179,7 @@ export default class SDKVideo { try { __LOG__ && console.warn("handleLoaded2"); LogService.I.adStat(this.videoKey, this.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.show) - TAMgr.Ins.dot('video', { - ad_key: this.videoKey, - type: DOT_AD_STATUS.show - }) - if (sys.platform === sys.Platform.WECHAT_GAME && typeof qq == 'undefined') { + if (cc.sys.platform === cc.sys.WECHAT_GAME && typeof qq == 'undefined') { if (that.videoAd.isReady()) {//抖音、qq 没有 isReady that.show_time = Date.now(); await that.videoAd.show(); @@ -218,18 +210,10 @@ export default class SDKVideo { if (res && res.isEnded || res === undefined) { // 统计看视频成功 LogService.I.adStat(that.videoKey, that.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.complete) - TAMgr.Ins.dot('video', { - ad_key: that.videoKey, - type: DOT_AD_STATUS.complete - }) that.resolve && that.resolve({ type: 2 }); } else { // console.log("视频关闭时间:", t) LogService.I.adStat(that.videoKey, that.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.interrupt, t) - TAMgr.Ins.dot('video', { - ad_key: that.videoKey, - type: DOT_AD_STATUS.interrupt - }) that.reject && that.reject({ ...ShareVideoError.VideoQuit }); } if (typeof my != 'undefined') { @@ -237,7 +221,7 @@ export default class SDKVideo { } else { that.videoAd.offClose(that.handleClose); } - + that.preloadVideo(that.adUnitId); that._isPlaying = false; that._isErrored = false; } @@ -246,11 +230,15 @@ export default class SDKVideo { __LOG__ && console.warn('====> PCSDK WxVideo 加载视频广告失败', err); let that = SDKVideo.I; LogService.I.adStat(that.videoKey, that.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.fail) - TAMgr.Ins.dot('video', { - ad_key: that.videoKey, - type: DOT_AD_STATUS.fail - }) - that.reject && that.reject({ ...ShareVideoError.VideoFail }); + // that.reject && that.reject({ ...ShareVideoError.VideoFail }); + if (that.reject) { + if (that.videoAd) + that.reject({ ...ShareVideoError.VideoFail }) + else { + let fail = { code: 1010, msg: '查看次数过多,请稍后再看!' } + that.reject({ ...fail }) + } + } if (typeof my != 'undefined') { } else { diff --git a/wxsdk/utils/RandomUtils.ts b/wxsdk/utils/RandomUtils.ts index 48e6730..d3d8d24 100644 --- a/wxsdk/utils/RandomUtils.ts +++ b/wxsdk/utils/RandomUtils.ts @@ -20,7 +20,7 @@ export default class RandomUtils { static rand(min: number, max: number) { min = min || 0; max = max || 10000; - return Math.floor(Math.random() * 10000) % (max - min) + min; + return Math.floor(Math.random() * 10000) % (max - min) + min; } static rang(min: number, max: number) { @@ -30,5 +30,4 @@ export default class RandomUtils { static randFloat(min: number, max: number) { return parseFloat((Math.random() * (max - min) + min).toFixed(2)); } - } diff --git a/wxsdk/utils/SDKUtils.ts b/wxsdk/utils/SDKUtils.ts index 8c9b57d..42e0ab4 100644 --- a/wxsdk/utils/SDKUtils.ts +++ b/wxsdk/utils/SDKUtils.ts @@ -65,6 +65,7 @@ export default class SDKUtils { // 兼容方式 - 版本比较 static compareVersion(v1: any, v2: any) { + // console.log("compareVersion", v1, v2) v1 = v1.split('.'); v2 = v2.split('.'); let len = Math.max(v1.length, v2.length); diff --git a/wxsdk/utils/SignUtils.ts b/wxsdk/utils/SignUtils.ts index 3aa60cd..3c5051b 100644 --- a/wxsdk/utils/SignUtils.ts +++ b/wxsdk/utils/SignUtils.ts @@ -11,7 +11,7 @@ export default class SignUtils { createSign(params: any) { let signStr = this.createQuery(params) + '' + GAMEDATA.appkey; - // console.error("signStr",signStr) + // console.error("signStr:::"+ signStr) return Md5.hashStr(signStr); } @@ -71,7 +71,7 @@ export default class SignUtils { let query = ''; for (let i = 0, len = keys.length; i < len; i++) { // 为空,为 0的参数不参与签名,参数名为ver,pkv的参数不参与签名, 字符集为 utf-8 - 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 + if (!params[keys[i]] || params[keys[i]] === '0' || keys[i] === 'ver' || keys[i] === 'pkv') continue key = keys[i]; i && (query += ''); if (SDKUtils.isArray(params[key])) { diff --git a/wxsdk/utils/StorageUtils.ts b/wxsdk/utils/StorageUtils.ts index 2275cf6..94d98f0 100644 --- a/wxsdk/utils/StorageUtils.ts +++ b/wxsdk/utils/StorageUtils.ts @@ -9,11 +9,7 @@ export default class StorageUtils { private store: any = null constructor() { - if (typeof localStorage === 'object') - this.store = new Storage; - - if (typeof (wx) != "undefined") - this.store = new WxStorage; + this.store = cc.sys.localStorage; } private __isExpired(entity: any) { diff --git a/wxsdk/wx/Version.ts b/wxsdk/wx/Version.ts index 5a3e6c9..43edb08 100644 --- a/wxsdk/wx/Version.ts +++ b/wxsdk/wx/Version.ts @@ -2,20 +2,23 @@ import { __LOG__ } from "../base/SDKConst"; enum PlatformType { WX = 'wx', - QQ = 'qq' + QQ = 'qq', + MY = 'my' } enum Platform{ - PlatformType = 'wx' + PlatformType = 'my' } export default class Version { private DEFUALT = '0.0.0'; private VERSION = { createRewardedVideoAd: { [PlatformType.WX]: '2.0.4', - [PlatformType.QQ]: '0.1.26' + [PlatformType.QQ]: '0.1.26', + [PlatformType.MY]: '10.3.70' }, createInterstitialAd: { - [PlatformType.WX]: '2.6.0' + [PlatformType.WX]: '2.6.0', + [PlatformType.MY]: '10.3.66' }, createFeedbackButton: { [PlatformType.WX]: '2.1.2' @@ -25,7 +28,8 @@ export default class Version { }, createBannerAd: { [PlatformType.WX]: '2.0.4', - [PlatformType.QQ]: '0.1.26' + [PlatformType.QQ]: '0.1.26', + [PlatformType.MY]: '10.3.66' }, createGameBanner: { [PlatformType.WX]: '2.7.5' diff --git a/wxsdk/wx/WxApi.ts b/wxsdk/wx/WxApi.ts index cec8d00..a496f4d 100644 --- a/wxsdk/wx/WxApi.ts +++ b/wxsdk/wx/WxApi.ts @@ -62,7 +62,7 @@ export default class WxApi { if (!this.canIUse(Version.I.getVBannerAd())) return null; adIntervals = adIntervals || 30; - return wx.createBannerAd({ + return my.createBannerAd({ adUnitId, style }); @@ -84,8 +84,9 @@ export default class WxApi { * 创建插屏广告组件 */ createInterstitialAd(adUnitId: string) { - if (!this.canIUse(Version.I.getVInterstitialAd())) return null; - return wx.createInterstitialAd({ + // if (!this.canIUse(Version.I.getVInterstitialAd())) return null; + if (typeof my === 'undefined') return null + return my.createInterstitialAd({ adUnitId }); } @@ -116,7 +117,7 @@ export default class WxApi { createRewardedVideoAd(adUnitId: string) { if (!this.canIUse(Version.I.getVRewardedVideoAd())) return null; - return wx.createRewardedVideoAd({ + return my.createRewardedAd({ adUnitId }); } @@ -163,10 +164,10 @@ export default class WxApi { } vibrateShort() { - if (!this.canIUse(Version.I.getVVibrate())) return Promise.reject(null); + // if (!this.canIUse(Version.I.getVVibrate())) return Promise.reject(null); return new Promise((resolve, reject) => { - wx.vibrateShort({ + my.vibrateShort({ success: () => { resolve(1); }, @@ -299,16 +300,25 @@ export default class WxApi { */ login(): Promise { return new Promise((resolve, reject) => { - wx.login({ - success: (ret: any) => { - resolve(ret.code); + // wx.login({ + // success: (ret: any) => { + // resolve(ret.code); + // }, + // fail: (err: any) => { + // reject(err); + // WxApi.I.setAuthorize({ + // errorTip: 'wx.login fail', + // ...err + // }); + // } + // }); + my.getAuthCode({ + scopes: 'auth_base', + success: (res) => { + resolve(res.authCode); }, fail: (err: any) => { reject(err); - WxApi.I.setAuthorize({ - errorTip: 'wx.login fail', - ...err - }); } }); }); @@ -371,8 +381,8 @@ export default class WxApi { /** * 米大师充值 */ - requestMidasPayment(params: { mode: string; env: number; offerId: string; currencyType: string; platform: string; buyQuantity: number; zoneId: string,outTradeNo:string }): Promise { - let { mode, env, offerId, currencyType, platform, buyQuantity, zoneId,outTradeNo } = params; + requestMidasPayment(params: { mode: string; env: number; offerId: string; currencyType: string; platform: string; buyQuantity: number; zoneId: string }): Promise { + let { mode, env, offerId, currencyType, platform, buyQuantity, zoneId } = params; console.warn('====> PCSDK WxApi requestMidasPayment 支付参数', { mode, env, @@ -380,8 +390,7 @@ export default class WxApi { currencyType, platform, buyQuantity, - zoneId, - outTradeNo + zoneId }); return new Promise((resolve, reject) => { wx.requestMidasPayment({ @@ -392,7 +401,6 @@ export default class WxApi { platform, buyQuantity, zoneId, - outTradeNo, success: ret => { if (ret && ret.errMsg === 'requestMidasPayment:ok') resolve(ret); diff --git a/wxsdk/wx/WxBanner.ts b/wxsdk/wx/WxBanner.ts index 24fda0e..d85dda2 100644 --- a/wxsdk/wx/WxBanner.ts +++ b/wxsdk/wx/WxBanner.ts @@ -42,7 +42,15 @@ export default class WxBanner { private queue: Function[] = []; private isEnd: boolean = false; - create(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean ,isCreate?:boolean}) { + create(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { + // console.log('wxbanner can not') + // console.log(my.env.clientVersion()) + if (SDKUtils.compareVersion(my.env.clientVersion, '10.3.66') < 0) return null; + // let a = my.env.clientVersion() + // console.log(a) + // if (!WxApi.I.canIUse(Version.I.getVBannerAd())) + // console.log('wxbanner can') + this.bannerParams = opts || {}; if (opts && opts.bannerWidth) { this.bannerWidth = opts.bannerWidth; @@ -67,24 +75,19 @@ export default class WxBanner { let style = { top: 0, left: (WxSystem.I.winWidth - this.bannerWidth) / 2, width: this.bannerWidth }; style = { ...style, - top: 0 + this.bannerParams.offsetY, + top: WxSystem.I.winHeight - 100, }; // 创建并判断是否存在 // if (this.bannerParams.type === 2) // this.bannerAd = wx.createGameBanner({ adUnitId, style: { left: style.left, top: this.bannerHeight } }); // else if (this.bannerAd) { - if(opts && opts.isCreate){ - //重新创建 - console.log("重新创建banner") - }else{ - if (!opts || (opts && !opts.isOff)) { - this.show(false); - } - return + if (!opts || (opts && !opts.isOff)) { + this.show(false); } + return } - this.bannerAd = wx.createBannerAd({ adUnitId, style, adIntervals: this.bannerParams.adIntervals }); + this.bannerAd = my.createBannerAd({ adUnitId, style, adIntervals: this.bannerParams.adIntervals }); LogService.I.adStat('banner', this.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.request) if (!this.bannerAd) { WxBanner.I.handleQueue(); @@ -204,6 +207,7 @@ export default class WxBanner { let that = WxBanner.I; that.unbind(); that._isErrored = true; + that.bannerAd?.destroy(); that.bannerAd = null; that.handleQueue() LogService.I.adStat('banner', that.adUnitId, DOT_AD_TYPE.banner, DOT_AD_STATUS.fail) @@ -213,9 +217,9 @@ export default class WxBanner { private unbind() { if (this.bannerAd) { - this.bannerAd.offLoad(this.onLoad); - this.bannerAd.offError(this.onError); - this.bannerAd.offResize(this.onResize); + // this.bannerAd.offLoad(this.onLoad); + // this.bannerAd.offError(this.onError); + // this.bannerAd.offResize(this.onResize); } } diff --git a/wxsdk/wx/WxCustom.ts b/wxsdk/wx/WxCustom.ts index da628bb..89c76c4 100644 --- a/wxsdk/wx/WxCustom.ts +++ b/wxsdk/wx/WxCustom.ts @@ -178,9 +178,9 @@ export default class WxCustom { private unbind() { if (this.customAd) { - this.customAd.offLoad(this.onLoad); - this.customAd.offClose(this.onClose); - this.customAd.offError(this.onError); + // this.customAd.offLoad(this.onLoad); + // this.customAd.offClose(this.onClose); + // this.customAd.offError(this.onError); } } diff --git a/wxsdk/wx/WxInit.ts b/wxsdk/wx/WxInit.ts index 9cc94a7..7684372 100644 --- a/wxsdk/wx/WxInit.ts +++ b/wxsdk/wx/WxInit.ts @@ -15,15 +15,15 @@ export default class WxInit { private constructor() { this.onlineTime = DateUtils.nowTime; - wx.onShow(this.onShow.bind(this)); - wx.onHide(this.onHide.bind(this)); - wx.onNetworkStatusChange(this.onNetworkStatusChange.bind(this)); + my.onShow(this.onShow.bind(this)); + my.onHide(this.onHide.bind(this)); + my.onNetworkStatusChange(this.onNetworkStatusChange.bind(this)); } init() { let { platform } = WxSystem.I.SystemData; let launchData = WxLaunch.I.LaunchData; - console.log("启动信息", JSON.stringify(launchData)); + console.log("启动信息", launchData); let { query, scene, referrerInfo } = launchData; let { invite_type, @@ -41,7 +41,6 @@ export default class WxInit { // 抖音投放相关信息 clue_token, ad_id, - promotion_id, creative_id, advertister_id, request_id @@ -59,10 +58,6 @@ export default class WxInit { if (ad_id) { fromChannel = ad_id; } - // 设置抖音投放转化跟踪 v2 - if(promotion_id){ - fromChannel = promotion_id; - } //定向分享统计 if (shareMessageToFriendScene && shareMessageToFriendScene >= 0 && shareMessageToFriendScene <= 50) { diff --git a/wxsdk/wx/WxLaunch.ts b/wxsdk/wx/WxLaunch.ts index d3e89ac..1cb8e53 100644 --- a/wxsdk/wx/WxLaunch.ts +++ b/wxsdk/wx/WxLaunch.ts @@ -3,7 +3,8 @@ export default class WxLaunch { private data: LaunchInfoSyncReturnValue; private constructor() { - this.data = wx.getLaunchOptionsSync(); + this.data = my.getLaunchOptionsSync(); + // console.log('lauch--',this.data); } get LaunchData() { diff --git a/wxsdk/wx/WxLogin.ts b/wxsdk/wx/WxLogin.ts index ed857e5..112fc5c 100644 --- a/wxsdk/wx/WxLogin.ts +++ b/wxsdk/wx/WxLogin.ts @@ -8,7 +8,7 @@ import LogService from "../service/LogService"; import { DOT_SHARE_TYPE } from "../base/SDKEnum"; import ShareVideoService from "../service/ShareVideoService"; import OnlineService from "../service/OnlineService"; -import AlipayApi from "../alipay/AlipayApi"; +import AlipayApi from '../alipay/AlipayApi'; export default class WxLogin { /** @@ -18,21 +18,25 @@ export default class WxLogin { * tip2:必须先调用wxLogin才能使用getUserInfo */ async login(isAuthorize: boolean): Promise { - if (typeof my !== 'undefined') { + + if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { + return + } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { + let self = this; return new Promise(async (resolve, reject) => { - console.log("-----login4-------") - let code = await AlipayApi.I.login(); - console.log("-----login5-------") - console.log(code) if (isAuthorize) { AlipayApi.I.getUserinfo() - .then((ret: any) => this.authedlogin(ret, code, resolve, reject)) - .catch((err: any) => this.weakLogin(err, code, resolve, reject)); + .then((ret: any) => this.authedlogin(ret, ret.authCode, resolve, reject)) + .catch(async (err: any) => { + let code = await AlipayApi.I.login(); + self.weakLogin(err, code, resolve, reject); + }); } else { - this.weakLogin({ errCode: 1, msg: '默认未授权登录' }, code, resolve, reject) + let code = await AlipayApi.I.login(); + self.weakLogin({ errCode: 1, msg: '默认未授权登录' }, code, resolve, reject) } }); - } else { + } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { return new Promise(async (resolve, reject) => { let code = await WxApi.I.login(); if (isAuthorize) { @@ -107,9 +111,7 @@ export default class WxLogin { * @param isAuthorize 是否授权:true=已授权 false=没有授权成功 */ private handleLogin(data: any, resolve: any, isAuthorize: boolean) { - // console.log("登录请求结果data", data) - - console.log("-----login5-------") + console.log("登录请求结果data"+JSON.stringify(data)) if (data) { // 设置登录信息 if (data.data) { @@ -135,13 +137,11 @@ export default class WxLogin { } try { //修改时间后会报错,未找到原因 this.handleExpire(expire) + // 支付宝会报错,如有自定义分享请解决 + // ShareVideoService.I.forward() } catch (error) { console.log("handleExpire_error", error) } - // 支付宝没有 - if(typeof my == 'undefined'){ - ShareVideoService.I.forward() - } } } resolve(data) @@ -209,11 +209,7 @@ export default class WxLogin { refToken: reftoken, expire, }); - try { //修改时间后会报错,未找到原因 - this.handleExpire(expire) - } catch (error) { - console.log("handleExpire_error", error) - } + this.handleExpire(expire) }) } diff --git a/wxsdk/wx/WxPay.ts b/wxsdk/wx/WxPay.ts index 12cd525..3bd0674 100644 --- a/wxsdk/wx/WxPay.ts +++ b/wxsdk/wx/WxPay.ts @@ -23,8 +23,7 @@ export default class WxPay { offerId: OfferId, currencyType: CurrencyType, buyQuantity: params.money / 10, - zoneId: ZoneId, - outTradeNo:params.orderid + zoneId: ZoneId }; let extend = ""; for (let key in opts) { @@ -49,7 +48,7 @@ export default class WxPay { WxApi.I.requestMidasPayment(pms) .then(() => this.handlePaySuccess({ ...params, platform }, opts, resolve, reject)) .catch(err => this.handlePayError({ ...params, platform }, opts, err, reject)); - } else { + }else{ reject(res); } }) @@ -91,7 +90,7 @@ export default class WxPay { } private handlePayError(data: { payid: string, goodid: string, money: number; orderid: string, platform: string }, opts, err: any, reject: any) { - console.log("handlePayError支付失败", JSON.stringify(err)); + console.log("支付失败", JSON.stringify(err)); let type = 2; if (err.errCode + '' == '1') { type = 3; diff --git a/wxsdk/wx/WxSystem.ts b/wxsdk/wx/WxSystem.ts index c128f16..597590a 100644 --- a/wxsdk/wx/WxSystem.ts +++ b/wxsdk/wx/WxSystem.ts @@ -3,7 +3,8 @@ export default class WxSystem { private data: SystemInfoSyncReturnValue; private constructor() { - this.data = wx.getSystemInfoSync(); + this.data = my.getSystemInfoSync(); + // console.log('WxSystem',this.data) } get SystemData() { @@ -42,7 +43,8 @@ export default class WxSystem { } get SDKVersion() { - return this.data.SDKVersion || this.data.version; + //version 是支付宝返回的 + return this.data.SDKVersion||this.data.version; } get brand() { -- libgit2 0.21.0