Commit cfd1e4dbef2a483b283303561cdf2b4104c3b4f4

Authored by 宋庆平
1 parent 3938c669
Exists in zfb_waibu_linshi

精简版sdk接入

sdk/Analytics.ts
@@ -102,6 +102,32 @@ export class Analytics { @@ -102,6 +102,32 @@ export class Analytics {
102 return WXSDK.stat.consume(id, typ, nums, gsne) 102 return WXSDK.stat.consume(id, typ, nums, gsne)
103 } 103 }
104 104
  105 + /**
  106 + * 游戏行为数据提交(玩一玩)
  107 + * @param action_code 用户在游戏中的行动编码
  108 + * @param action_finish_channel 用户完成行动的渠道
  109 + * @param action_finish_date 用户完成时间
  110 + * @param status 上报的结果 0成功 其他失败
  111 + */
  112 + AlipayGameCenter(action_code:string,action_finish_channel:string,action_finish_date:string,status:string) {
  113 + WXSDK.stat.AlipayGameCenter(action_code,action_finish_channel,action_finish_date,status);
  114 +
  115 + }
  116 +
  117 + /**
  118 + * 支付行为上报
  119 + * @param orderid 订单号,游戏方订单号
  120 + * @param goodid 游戏方商品ID
  121 + * @param goodname 游戏方商品名字
  122 + * @param money 支付金额,单位分
  123 + * @param paytype 支付方式,1客服消息支付 3米大师支付 4小程序支付 6二维码支付 7字节钱包 8QQ钱包 9华为钱包 10支付宝小游戏支付 11支付宝小程序(跳转到另外一个小程序支付)13美团支付
  124 + * @param paystatus 1支付成功 2支付失败
  125 + * @param ordertype 支付平台,android,ios,windows,mac
  126 + */
  127 + orderLogReport(orderid: string, goodid: string, goodname: string, money: number, paytype: number, paystatus: number, ordertype: string) {
  128 + WXSDK.stat.orderLogReport(orderid, goodid, goodname, money, paytype, paystatus, ordertype)
  129 + }
  130 +
105 131
106 } 132 }
107 export enum EventKey { 133 export enum EventKey {
sdk/SDKTools.ts
@@ -371,11 +371,4 @@ export class SDKTools { @@ -371,11 +371,4 @@ export class SDKTools {
371 * 中台自定义配置表 371 * 中台自定义配置表
372 */ 372 */
373 export enum OnlineKeys { 373 export enum OnlineKeys {
374 - isOpenInterstitialAdId = 'isOpenInterstitialAdId',  
375 - shareRandom = 'shareRandom',  
376 - switch_draw = 'switch_draw',  
377 - switch_banner = 'switch_banner',  
378 - switch_grid = 'switch_grid',  
379 - calendar_level_max = 'calendar_level_max',  
380 - over_show_ad = 'over_show_ad'  
381 } 374 }
382 \ No newline at end of file 375 \ No newline at end of file
wxsdk/WXSDK.ts
@@ -7,6 +7,7 @@ import LogService from "./service/LogService"; @@ -7,6 +7,7 @@ import LogService from "./service/LogService";
7 import AdService from "./service/AdService"; 7 import AdService from "./service/AdService";
8 import OnlineService from "./service/OnlineService"; 8 import OnlineService from "./service/OnlineService";
9 import WxInterstitial from "./wx/WxInterstitial"; 9 import WxInterstitial from "./wx/WxInterstitial";
  10 +import { GAMEDATA } from "./base/SDKConst";
10 export default class WXSDK { 11 export default class WXSDK {
11 public static get isWx(): boolean { 12 public static get isWx(): boolean {
12 return typeof (my) != "undefined" 13 return typeof (my) != "undefined"
@@ -35,40 +36,20 @@ export default class WXSDK { @@ -35,40 +36,20 @@ export default class WXSDK {
35 } 36 }
36 37
37 38
38 - public static async init() {  
39 - // if (this.isWx) {  
40 - // WxInit.I.init();  
41 - // //视频预加载 启动预加载视频会闪屏  
42 - // // setTimeout(() => {  
43 - // // WxInterstitial.initInterstitialAd();//插屏预加载  
44 - // // ShareVideoService.I.preloadVideo();  
45 - // // }, 2000);  
46 - // if (this.isWx) {  
47 - // setTimeout(() => {  
48 - // WxInterstitial.initInterstitialAd();//插屏预加载  
49 - // ShareVideoService.I.preloadVideo();  
50 - // }, 2000);  
51 - // }  
52 - // }  
53 - // DataService.I.updateTodayOnlineTime();  
54 - // await this.game.env();  
55 - // if (this.isWx) {  
56 - // ShareVideoService.I.init();  
57 - // }  
58 - // return Promise.resolve();  
59 - if (cc.sys.platform === cc.sys.ALIPAY_GAME || cc.sys.platform === cc.sys.WECHAT_GAME) {  
60 - WxInit.I.init();  
61 - // 视频预加载 启动预加载视频会闪屏  
62 - // if (cc.sys.platform === cc.sys.WECHAT_GAME && typeof qq == 'undefined') {  
63 - if (typeof qq == 'undefined') {  
64 - setTimeout(() => {  
65 - WXSDK.ad.initInterstitialAd();//插屏预加载  
66 - ShareVideoService.I.preloadVideo();  
67 - }, 2000); 39 + public static async init(gameData?:any) {
  40 + if(gameData) {
  41 + let keys = Object.keys(gameData);
  42 + for(let i = 0; i < keys.length; i++) {
  43 + let key = keys[i];
  44 + GAMEDATA[key] = gameData[key];
68 } 45 }
  46 + }
  47 + if (typeof wx!='undefined' || typeof my!='undefined') {
  48 + WxInit.I.init();
69 DataService.I.updateTodayOnlineTime(); 49 DataService.I.updateTodayOnlineTime();
70 await this.game.env(); 50 await this.game.env();
71 - ShareVideoService.I.init(); 51 +
  52 + await this.game.login(false);
72 } 53 }
73 return Promise.resolve(); 54 return Promise.resolve();
74 } 55 }
wxsdk/base/SDKConst.ts
1 // 游戏配置数据 只需要改动这里的配置信息 1 // 游戏配置数据 只需要改动这里的配置信息
2 // 2021003184609526 2 // 2021003184609526
3 export const GAMEDATA = { 3 export const GAMEDATA = {
4 - game_id: '10150',//游戏id 4 + game_id: 'xxxxx',//游戏id
5 isDebug: false, 5 isDebug: false,
6 - channel_id: '10150',//渠道id 暂时和游戏id一致 6 + channel_id: 'xxxxx',//渠道id 暂时和游戏id一致
7 version: '1.0.0', //版本号 中台控制正式还是测试服,尽量保持和小游戏版本一致 7 version: '1.0.0', //版本号 中台控制正式还是测试服,尽量保持和小游戏版本一致
8 - appkey: '761bdbb773c59e545ac729adec818ddc',//中台appkey  
9 - interstitialAdId: 'ad_tiny_2021004125691158_202311162200070802',//插屏ID  
10 - bannerId: 'ad_tiny_2021004125691158_202311162200070801',//banner 8 + appkey: '761bdbb773c59e545ac729adec818aaa',//中台appkey
  9 + interstitialAdId: '',//插屏ID
  10 + bannerId: '',//banner
11 customId: '',//原生模板单个 11 customId: '',//原生模板单个
12 - videoAd: 'ad_tiny_2021004125691158_202311162200070775',//初始化视频广告id  
13 - shareMessageToFriend: { // 暂时只支持一个场景值  
14 - scene: 0, //定向分享场景值1-50 配>0的会初始化  
15 - sharekey: 'shareMessageToFriendScene',//定向分享对应后台的分享key  
16 - share_id: 26,//定向分享对应后台的分享key  
17 - }, 12 + videoAd: '',//初始化视频广告id
18 default_share: { 13 default_share: {
19 - content: '还记得童年的泡泡龙吗?一起来怀旧吧~ 这个可以不?',  
20 - icon: 'https://cdn-wxsdk.miso-lab.com/f0/5653094b6b7826c8afd813d12735e3.jpg',  
21 - id: '9999', 14 + content: '默认分享标题',
  15 + icon: '默认分享图片的url',
  16 + id: '9999',//写死9999
22 key: 'default', 17 key: 'default',
23 title: '默认', 18 title: '默认',
24 typ: 1, 19 typ: 1,
25 videoid: '' 20 videoid: ''
26 - },  
27 - subscribeIds: ['yB-vq0DvOhazzDbvS1UzttLMIQ50Z_i0n8st6yEZYkw', '4al8p3UBb3xqn7TYN1J5wYtKrCbFc2MYESAv1vWi-C0'], //, 'cMo71MjAFzGM2MEpRw2p8T5jJaEhXJUfiIjoOB5oO70'],  
28 - versionContent: '1、开启每日幸运转盘活动\r\n2、针对部分玩家出现的卡顿问题进行修复' 21 + }
29 } 22 }
30 23
31 // sdk版本 24 // sdk版本
@@ -84,6 +77,7 @@ export const HostKeys = { @@ -84,6 +77,7 @@ export const HostKeys = {
84 client_log: 'logstores/client_log/track', //客户端日志 77 client_log: 'logstores/client_log/track', //客户端日志
85 consume: 'logstores/consume/track', //资源上报 78 consume: 'logstores/consume/track', //资源上报
86 daystay: 'logstores/daystay/track', //300s停留上报 79 daystay: 'logstores/daystay/track', //300s停留上报
  80 + zfb_game_center: "logstores/zfb_game_center/track",//支付宝游戏行为数据提交(玩一玩)
87 81
88 //登录 82 //登录
89 Login: 'api/login', //登录 83 Login: 'api/login', //登录
@@ -113,6 +107,7 @@ export const HostKeys = { @@ -113,6 +107,7 @@ export const HostKeys = {
113 orderReport: 'api/order/v2/mimas/new', //订单信息上报 107 orderReport: 'api/order/v2/mimas/new', //订单信息上报
114 orderQuery: 'api/order/query', //订单信息查询 108 orderQuery: 'api/order/query', //订单信息查询
115 preorder: 'api/order/v2/preorder', //获取支付方式 109 preorder: 'api/order/v2/preorder', //获取支付方式
  110 + orderLogReport: 'api/order/v2/logreport', //支付行为上报
116 // 111 //
117 goodslist: 'api/v2/goodslist', //商品列表 112 goodslist: 'api/v2/goodslist', //商品列表
118 113
wxsdk/http/SDKApi.ts
@@ -78,13 +78,15 @@ export class SDKApi { @@ -78,13 +78,15 @@ export class SDKApi {
78 public static daystay = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.daystay, ...args); 78 public static daystay = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.daystay, ...args);
79 79
80 80
  81 + public static zfb_game_center = (...args) => SDKHttp.httpGet(DataService.I.DotApi, HostKeys.zfb_game_center, ...args);
  82 +
81 // OrderApi 83 // OrderApi
82 public static pay = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderReport, ...args); 84 public static pay = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderReport, ...args);
83 public static orderQuery = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderQuery, ...args); 85 public static orderQuery = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderQuery, ...args);
84 public static preorder = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.preorder, ...args); 86 public static preorder = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.preorder, ...args);
85 87
86 public static goodslist = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.goodslist, ...args); 88 public static goodslist = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.goodslist, ...args);
87 - 89 + public static orderLogReport = (...args) => SDKHttp.httpPost(DataService.I.OrderApi, HostKeys.orderLogReport, ...args);
88 90
89 91
90 //阿里增量任务 92 //阿里增量任务
wxsdk/service/GameService.ts
@@ -19,11 +19,7 @@ export default class GameService { @@ -19,11 +19,7 @@ export default class GameService {
19 __LOG__ && console.log("版本信息", data); 19 __LOG__ && console.log("版本信息", data);
20 let num = data.data ? data.data.env ? data.data.env : 2 : 2; 20 let num = data.data ? data.data.env ? data.data.env : 2 : 2;
21 DataService.I.setEnvEnum(+num) 21 DataService.I.setEnvEnum(+num)
22 - // DataService.I.setCdnUrl(data.res_url || '');  
23 } 22 }
24 - // 设置在线参数请求  
25 - // let isAutoOnlineUse = CfgManager.I.config.IsOnlineAutoUse;  
26 - // isAutoOnlineUse && OnlineService.I.updateOnlineConfig().then(() => EventCenter.I.emit(EventEnum.ONLINE_SUCCESS));  
27 resolve(data); 23 resolve(data);
28 }).catch((err: any) => { 24 }).catch((err: any) => {
29 reject(err); 25 reject(err);
wxsdk/service/LogService.ts
@@ -66,6 +66,9 @@ export default class LogService { @@ -66,6 +66,9 @@ export default class LogService {
66 private get UserId() { 66 private get UserId() {
67 return DataService.I.UserId; 67 return DataService.I.UserId;
68 } 68 }
  69 + private get Token() {
  70 + return DataService.I.Token;
  71 + }
69 72
70 private get OpenId() { 73 private get OpenId() {
71 return DataService.I.OpenId; 74 return DataService.I.OpenId;
@@ -513,6 +516,44 @@ export default class LogService { @@ -513,6 +516,44 @@ export default class LogService {
513 } 516 }
514 517
515 518
  519 +
  520 + /**
  521 + * 游戏行为数据提交(玩一玩)
  522 + * @param action_code 用户在游戏中的行动编码
  523 + * @param action_finish_channel 用户完成行动的渠道
  524 + * @param action_finish_date 用户完成时间
  525 + * @param status 上报的结果 0成功 其他失败
  526 + */
  527 + AlipayGameCenter(action_code:string,action_finish_channel:string,action_finish_date:string,status:string) {
  528 + let fun = () => SDKApi.zfb_game_center({
  529 + openid: this.OpenId,
  530 + uid: this.UserId,
  531 + action_code,action_finish_channel,action_finish_date,status
  532 + })
  533 + this.checkLogin(fun);
  534 + }
  535 +
  536 + /**
  537 + * 支付行为上报
  538 + * @param orderid 订单号,游戏方订单号
  539 + * @param goodid 游戏方商品ID
  540 + * @param goodname 游戏方商品名字
  541 + * @param money 支付金额,单位分
  542 + * @param paytype 支付方式,1客服消息支付 3米大师支付 4小程序支付 6二维码支付 7字节钱包 8QQ钱包 9华为钱包 10支付宝小游戏支付 11支付宝小程序(跳转到另外一个小程序支付)13美团支付
  543 + * @param paystatus 1支付成功 2支付失败
  544 + * @param ordertype 支付平台,android,ios,windows,mac
  545 + */
  546 + orderLogReport(orderid: string, goodid: string, goodname: string, money: number, paytype: number, paystatus: number, ordertype: string) {
  547 + let fun = () => SDKApi.orderLogReport({
  548 + ...this.buildParams(),
  549 + openid: this.OpenId,
  550 + uid: this.UserId,
  551 + token: this.Token,
  552 + orderid, goodid, goodname, money, paytype, paystatus, ordertype
  553 + })
  554 + this.checkLogin(fun);
  555 + }
  556 +
516 /** 557 /**
517 * 构建登录/弱登录公用参数 558 * 构建登录/弱登录公用参数
518 */ 559 */
wxsdk/service/ShareVideoService.ts
@@ -32,12 +32,6 @@ export default class ShareVideoService { @@ -32,12 +32,6 @@ export default class ShareVideoService {
32 this.setShareVideoData(data); 32 this.setShareVideoData(data);
33 // console.log(JSON.stringify(data)) 33 // console.log(JSON.stringify(data))
34 SDKShare.I.updateShareMenu(true);//打开群分享 34 SDKShare.I.updateShareMenu(true);//打开群分享
35 -  
36 -  
37 - if (GAMEDATA.shareMessageToFriend.scene > 0) {  
38 - my.setMessageToFriendQuery({ shareMessageToFriendScene: GAMEDATA.shareMessageToFriend.scene })  
39 - }  
40 -  
41 if (this.forwardKey) this.forward(this.forwardKey); 35 if (this.forwardKey) this.forward(this.forwardKey);
42 } 36 }
43 37
wxsdk/wx/WxInit.ts
@@ -59,12 +59,6 @@ export default class WxInit { @@ -59,12 +59,6 @@ export default class WxInit {
59 fromChannel = ad_id; 59 fromChannel = ad_id;
60 } 60 }
61 61
62 - //定向分享统计  
63 - if (shareMessageToFriendScene && shareMessageToFriendScene >= 0 && shareMessageToFriendScene <= 50) {  
64 - share_key = GAMEDATA.shareMessageToFriend.sharekey;  
65 - share_id = GAMEDATA.shareMessageToFriend.share_id;  
66 - }  
67 -  
68 __LOG__ && console.warn(`====> PCSDK wxinit query user_invite_uid:${user_invite_uid}; fromChannel:${fromChannel}; channelId:${fromChannel}; scene:${scene}; share_id:${share_id}; share_key:${share_key};`); 62 __LOG__ && console.warn(`====> PCSDK wxinit query user_invite_uid:${user_invite_uid}; fromChannel:${fromChannel}; channelId:${fromChannel}; scene:${scene}; share_id:${share_id}; share_key:${share_key};`);
69 63
70 // 设置sdk 数据的信息 64 // 设置sdk 数据的信息