game_Simulate.js
7.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//另一种在代码中引入JS文件的方式
// var newScript = document.createElement('script');
// newScript.setAttribute('type', 'text/javascript');
// newScript.setAttribute('src', 'Test2.js');
// document.getElementsByTagName('head')[0].appendChild(newScript);
document.write("<script type=\"text\/javascript\" src=\"youaiH5SDK.js\"><\/script>");
var game = {
/**
* code: {
INIT_SUCCESS: 1,
INIT_FAIL: -1,
LOGIN_SUCCESS: 10,
LOGIN_FAIL: -10,
LOGOUT_SUCCESS: 100,
LOGOUT_FAIL: -100,
SWITCH_SUCCESS: 1000,
SWITCH_FAIL: -1000,
PAY_SUCCESS: 2,//充值以服务端回调结果为准
PAY_FAIL: -2,
PAY_CANCEL:-3,//支付取消
EXIT_SUCCESS = 4,//退出成功
EXIT_CANCEL = -4//取消退出
}
* @param {*} code 为youaiH5SDK.code中对应值
* @param {*} msg
*/
callback: function (code, msg) {
console.log(code, msg);
switch (code) {
case youaiH5SDK.code.INIT_SUCCESS:
console.log("game init success")
break;
case youaiH5SDK.code.LOGIN_SUCCESS:
console.log("game login success")
console.log("openId:" + msg.openId + "custom:" + msg.custom + "serverSign:" + msg.serverSign + "timestamp:" + msg.timestamp);
break;
case youaiH5SDK.code.LOGOUT_SUCCESS:
console.log("game logout success")
break;
case youaiH5SDK.code.SWITCH_SUCCESS:
console.log("game switch account success")
break;
case youaiH5SDK.code.PAY_SUCCESS:
console.log("game pay success")
break;
case youaiH5SDK.code.EXIT_SUCCESS:
//游戏处理退出逻辑
break;
}
},
init: function () {
var SDKInfo = {
"gameSimpleName": "fytx_test",
"sdkSimpleName": "huoshu_h5",
"sdkClientVersion": "1.0",
"sdkVersionCode": "V1_0",
"statisticsUrl": "",
"channelParameter1": "yy",
"channelParameter2": "yy2"
};
var param = window.location.search.substring(1);
console.log(param);
var params = param.split("&");
console.log(params);
for (var i = 0; i < params.length; i++) {
console.log(params[i]);
var values = params[i].split("=");
console.log(values);
switch (values[0]) {
case "ya_game":
SDKInfo.gameSimpleName = values[1];
break;
case "ya_sn":
SDKInfo.sdkSimpleName = values[1];
break;
case "ya_ssv":
SDKInfo.sdkVersionCode = values[1];
break;
case "ya_sv":
SDKInfo.sdkClientVersion = values[1];
break;
default:
break;
}
}
youaiH5SDK.init(SDKInfo, this.callback);
},
login: function () {
var param = "test";
youaiH5SDK.login(param);
},
logout: function () {
if (youaiH5SDK.hasLogout()) {
youaiH5SDK.logout();
}
},
switchAccount: function () {
if (youaiH5SDK.hasSwitchAccount()) {
console.log("end switch account");
youaiH5SDK.switchAccount();
}
},
submitInfo: function () {
/**
* 为youaiH5SDK.type中对应类型值
type: {
arriveEntrance: 1,//首屏日志
arriveLoadingZero: 2,//刚开始加载资源类型
arriveLoadingFinish: 3,//资源加载完成
arriveCreateRolePage: 4,//到达创建角色页面
arriveServerSelectPage: 5,//到达选服页面
enterServer: 6,//选服完成,点击进入对应服时
arriveFirstScene: 7,//到达游戏内第一场景时调用
enterGame: 8,//进入游戏时调用
createRole: 9,//创建角色时调用
upRoleLevel: 10//角色升级日志
}
*/
var submitType = youaiH5SDK.type.enterGame;
var roleInfo = {
"roleID": "15",
"roleName": "test",
"roleLevel": "15",
"roleSex": "test",
"serverID": "15",
"serverName": "test",
"roleCTime": "15",
"partyName": "test",
"roleType": "test",
"roleChangeTime": "test",
"vipLevel": "15",
"diamond": "15",
"moneyType": "test",
"custom": "test"
};
youaiH5SDK.submitData(submitType, roleInfo);
},
pay: function () {
var payInfo = {
"serverId": "15",
"serverName": "test",
"playerId": "15",
"playerName": "test",
"playerLevel": "15",
"postAmount": "15",
"openId":"123643",
"productId": "15",
"productName": "test",
"productDesc": "test",
"custom": "test",
"exchange": "15",
"otherInfo": "15",
"timeStamp": "15"
};
youaiH5SDK.pay(payInfo);
},
showExitDialog: function () {
if (youaiH5SDK.hasShowExitDialog()) {
youaiH5SDK.showExitDialog();
} else {
//游戏自己处理退出逻辑
youaiH5SDK.exitGame();
}
},
statistics: function () {
var data = [{ "headers": { "product": "roh5" }, "body": "2018-03-14 17:57:21|test|5|qd|dqd|xqd|22222|20qd|10|1050055" }];
var statisticsListener = {
onStatisticsSuccess: function () {
alert("Statistic success!");
},
onStatisticsFail: function () {
alert("Statistic fail!");
}
};
youaiH5SDK.statistics(data, statisticsListener);
},
expansionInterface: function () {
/**
* 传公共sdk扩展类型
* {
gameSetting:100,//功能设置
downloadMicroClent:101,//下载微端
share:102,//分享
focus:103,//关注
save2Desktop:104,//保存到桌面
realVerify:105,//实名认证
back2Game:106,//返回游戏
bindPhone:107,//绑定手机有奖接口
}
*/
var expansion_type = youaiH5SDK.expansion_type.gameSetting;//功能设置
/**
* {
code:0,//0:成功 其他为失败
message:"success",//返回描述
data:{//除了gameSetting类型,其他功能暂时不返回data字段
has_micro_client:0,//是否有微端 0:没有,1:有,2已经在微端中
is_share:0,//是否有分享接口 0:没有,1:有
is_focus:0,//是否有关注 0:没,1:有,2:已经关注
is_apple_pay:0,//是否开启苹果支付 0:不开启 1:开启
is_desktop:0,//是否有保存桌面 0:没有 1:有
is_switch_account:0,//是否有切换账号 0:没有 1有
is_realverify:0,//是否有实名认证 0:没有 1:有 2:已认证
is_super_kefu:0,//是否有超级客服 0:没 1:有
is_backtogame:0,//是否有返回按钮 0:没有,1:有
is_lock:0,//是否竖屏 0:研发默认样式 1:强制竖屏
is_focus_gift:0,//关注有礼 0:关闭 1:开启
is_bindphone:0//绑定手机 0:关闭 1:开启 2:已绑定手机
}
}
* @param {*} result
*/
var expansionCallBack = function(result){
}
youaiH5SDK.expansionInterface(expansion_type,"",expansionCallBack);
}
};