xuguohong

提交js对接资料

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