GSCSdkInterface.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. using System.Security.Cryptography;
  7. /// <summary>
  8. /// 接收 SDK 的回调消息,进行处理。
  9. /// 该脚本应关联到每一个场景的 "Main Camera" 对象,以能接收SDK回调的消息。
  10. /// 下面各方法中的逻辑处理,在游戏中应修改为真实的逻辑。
  11. /// </summary>
  12. public class GSCSdkInterface : MonoBehaviour
  13. {
  14. //iOS unity调用iOS层方法
  15. [DllImport("__Internal")]
  16. public static extern void __initIosSDK(string gameId, string cpId, string serverId, string appkey, string sandboxKey);
  17. [DllImport("__Internal")]
  18. public static extern void __iosLogin();
  19. [DllImport("__Internal")]
  20. public static extern void __iosLogout();
  21. [DllImport("__Internal")]
  22. public static extern void __iosUserInfo(string accesskey);
  23. [DllImport("__Internal")]
  24. public static extern void __iosIsRealnameAuth();
  25. [DllImport("__Internal")]
  26. public static extern void __iosGetSdkType();
  27. [DllImport("__Internal")]
  28. public static extern void __iosGetSdkChannel();
  29. [DllImport("__Internal")]
  30. public static extern void __iosGetSdkVersion();
  31. [DllImport("__Internal")]
  32. public static extern void __iosCreateRole(string roleid, string rolename);
  33. [DllImport("__Internal")]
  34. public static extern void __iosNotifyZone(string serverid, string servername, string roleid, string rolename);
  35. [DllImport("__Internal")]
  36. public static extern void __iosSetGameOpenUrl(string url);
  37. [DllImport("__Internal")]
  38. public static extern void __iosHeartbeatStart();
  39. [DllImport("__Internal")]
  40. public static extern void __iosHeartbeatStop();
  41. [DllImport("__Internal")]
  42. public static extern void __iosAgreementWithLicence();
  43. [DllImport("__Internal")]
  44. public static extern void __iosAgreementWithPrivacy();
  45. [DllImport("__Internal")]
  46. public static extern void __iosGeetest();
  47. [DllImport("__Internal")]
  48. public static extern void __iosAccountProtect();
  49. [DllImport("__Internal")]
  50. public static extern void __iosGetFreeUrl(string sourceUrl, string gameId, string appKey);
  51. [DllImport("__Internal")]
  52. public static extern void __iosPay(string productId, string outTradeNo, string money, string productName, string productCount, string description,string extension, string orderSign, string notifyUrl);
  53. //android unity调用java层方法
  54. public static void callSdkApi (string apiName, params object[] args)
  55. {
  56. using (AndroidJavaClass cls = new AndroidJavaClass("com.gsc.unityasdemo.GSCSdkCenter")) {
  57. cls.CallStatic (apiName, args);
  58. }
  59. }
  60. /**
  61. * android 支付接口
  62. * @param uid 用户的唯一标识(整型)
  63. * @param username 用户名或者email(唯一)
  64. * @param role 充值的角色信息
  65. * @param serverId 区服号
  66. * @param total_fee 充值金额
  67. * @param game_money 游戏币,需要用充值金额*充值比率
  68. * @param out_trade_no 充值订单号
  69. * @param subject 充值主题
  70. * @param body 充值描述
  71. * @param extension_info 附加信息,会在服务器异步回调中原样传回
  72. */
  73. public static void androidPay(long uid, string username, string role, string serverId,
  74. int total_fee, int game_money, string out_trade_no, string subject, string body, string extension_info, string notify_url, string order_sign)
  75. {
  76. #if UNITY_ANDROID
  77. callSdkApi ("pay", uid, username, role, serverId, total_fee, game_money, out_trade_no, subject, body, extension_info, notify_url, order_sign);
  78. #endif
  79. }
  80. /**
  81. * android获取设备指纹信息接口
  82. */
  83. public static void androidFingerprint()
  84. {
  85. #if UNITY_ANDROID
  86. callSdkApi ("getFingerprint");
  87. #endif
  88. }
  89. /**
  90. * android获取是否登录接口
  91. */
  92. public static void androidCheckLogin()
  93. {
  94. #if UNITY_ANDROID
  95. callSdkApi ("checkLogin");
  96. #endif
  97. }
  98. /**
  99. * android退出接口
  100. */
  101. public static void androidExit ()
  102. {
  103. #if UNITY_ANDROID
  104. callSdkApi ("exit");
  105. #endif
  106. }
  107. /**
  108. * iOS支付接口
  109. */
  110. public static void iOSPay(string product_id, string out_trade_no, int money, string subject, int game_money, string body, string extension_info, string order_sign, string notify_url)
  111. {
  112. #if UNITY_IOS
  113. __iosPay(product_id, out_trade_no, money, subject, game_money, body, extension_info, order_sign, notify_url);
  114. #endif
  115. }
  116. /**
  117. * iOS获取sdk的版本接口
  118. */
  119. public static void iOSSdkVersion()
  120. {
  121. #if UNITY_IOS
  122. __iosGetSdkVersion();
  123. #endif
  124. }
  125. /**
  126. * 初始化
  127. */
  128. public static void init(string merchant_id, string app_id, string server_id, string app_key, string sandboxKey)
  129. {
  130. Debug.Log("init");
  131. #if UNITY_IOS
  132. __initIosSDK(merchant_id, app_id, server_id, app_key, sandboxKey);
  133. #elif UNITY_ANDROID
  134. callSdkApi ("init", merchant_id, app_id, server_id, app_key);
  135. #endif
  136. }
  137. /**
  138. * 登录接口
  139. */
  140. public static void login ()
  141. {
  142. #if UNITY_IOS
  143. __iosLogin();
  144. #elif UNITY_ANDROID
  145. callSdkApi ("login");
  146. #endif
  147. }
  148. /**
  149. * 通知区服接口
  150. */
  151. public static void notifyZone(string server_id, string server_name, string role_id, string role_name)
  152. {
  153. #if UNITY_IOS
  154. __iosNotifyZone(server_id, server_name, role_id, role_name);
  155. #elif UNITY_ANDROID
  156. callSdkApi ("notifyZone", server_id, server_name, role_id, role_name);
  157. #endif
  158. }
  159. /**
  160. * 创角接口
  161. */
  162. public static void createRole(string role_name, string role_id)
  163. {
  164. #if UNITY_IOS
  165. __iosCreateRole(role_name, role_id);
  166. #elif UNITY_ANDROID
  167. callSdkApi ("createRole", role_id, role_name);
  168. #endif
  169. }
  170. /**
  171. * 停止心跳接口
  172. */
  173. public static void stopHeartbeat()
  174. {
  175. #if UNITY_IOS
  176. __iosHeartbeatStop();
  177. #elif UNITY_ANDROID
  178. callSdkApi ("stop");
  179. #endif
  180. }
  181. /**
  182. * 开始心跳接口
  183. */
  184. public static void startHeartbeat()
  185. {
  186. #if UNITY_IOS
  187. __iosHeartbeatStart();
  188. #elif UNITY_ANDROID
  189. callSdkApi ("start");
  190. #endif
  191. }
  192. /**
  193. * 获取sdk类型接口
  194. */
  195. public static void getSdkType()
  196. {
  197. #if UNITY_IOS
  198. __iosGetSdkType();
  199. #elif UNITY_ANDROID
  200. callSdkApi ("getSdkType");
  201. #endif
  202. }
  203. /**
  204. * 获取渠道号接口
  205. */
  206. public static void getChannelId()
  207. {
  208. #if UNITY_IOS
  209. __iosGetSdkChannel();
  210. #elif UNITY_ANDROID
  211. callSdkApi ("getChannelId");
  212. #endif
  213. }
  214. /**
  215. * 获取是否实名认证接口
  216. */
  217. public static void isRealNameAuth(){
  218. #if UNITY_IOS
  219. __iosIsRealnameAuth();
  220. #elif UNITY_ANDROID
  221. callSdkApi ("isRealNameAuth");
  222. #endif
  223. }
  224. /**
  225. * 登出接口
  226. */
  227. public static void logout()
  228. {
  229. #if UNITY_IOS
  230. __iosLogout();
  231. #elif UNITY_ANDROID
  232. callSdkApi ("logout");
  233. #endif
  234. }
  235. /**
  236. * 获取用户信息接口
  237. */
  238. public static void getUserInfo(string accesskey)
  239. {
  240. #if UNITY_IOS
  241. __iosUserInfo(accesskey);
  242. #elif UNITY_ANDROID
  243. callSdkApi ("getUserInfo");
  244. #endif
  245. }
  246. /**
  247. * 账号保护接口
  248. */
  249. public static void accountProtect ()
  250. {
  251. #if UNITY_IOS
  252. __iosAccountProtect();
  253. #elif UNITY_ANDROID
  254. callSdkApi ("accountProtect");
  255. #endif
  256. }
  257. /**
  258. * 显示用户协议界面接口
  259. */
  260. public static void showAgreementWithLicence ()
  261. {
  262. #if UNITY_IOS
  263. __iosAgreementWithLicence();
  264. #elif UNITY_ANDROID
  265. callSdkApi ("showAgreementWithLicence");
  266. #endif
  267. }
  268. /**
  269. * 显示隐私政策界面接口
  270. */
  271. public static void showAgreementWithPrivacy ()
  272. {
  273. #if UNITY_IOS
  274. __iosAgreementWithPrivacy();
  275. #elif UNITY_ANDROID
  276. callSdkApi ("showAgreementWithPrivacy");
  277. #endif
  278. }
  279. /**
  280. * 显示人机验证接口
  281. */
  282. public static void showGeetestView ()
  283. {
  284. #if UNITY_IOS
  285. __iosGeetest();
  286. #elif UNITY_ANDROID
  287. callSdkApi ("showGeetestView");
  288. #endif
  289. }
  290. //测试
  291. public static void showToast(string content)
  292. {
  293. #if UNITY_IOS
  294. #elif UNITY_ANDROID
  295. callSdkApi ("showToast", content);
  296. #endif
  297. }
  298. }