| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 | 
							- using UnityEngine;
 
- using System.Collections;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Runtime.InteropServices;
 
- using System.Security.Cryptography;
 
- /// <summary>
 
- /// 接收 SDK 的回调消息,进行处理。
 
- /// 该脚本应关联到每一个场景的 "Main Camera" 对象,以能接收SDK回调的消息。
 
- /// 下面各方法中的逻辑处理,在游戏中应修改为真实的逻辑。
 
- /// </summary>
 
- public class GSCSdkInterface : MonoBehaviour
 
- {
 
- 	//iOS unity调用iOS层方法
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __initIosSDK(string gameId, string cpId, string serverId, string appkey, string sandboxKey);
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosLogin();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosLogout();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosUserInfo(string accesskey);
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosIsRealnameAuth();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosGetSdkType();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosGetSdkChannel();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosGetSdkVersion();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosCreateRole(string roleid, string rolename);
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosNotifyZone(string serverid, string servername, string roleid, string rolename);
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosSetGameOpenUrl(string url);
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosHeartbeatStart();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosHeartbeatStop();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosAgreementWithLicence();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosAgreementWithPrivacy();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosGeetest();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosAccountProtect();
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosGetFreeUrl(string sourceUrl, string gameId, string appKey);
 
- 	[DllImport("__Internal")]
 
- 	public static extern void __iosPay(string productId, string outTradeNo, string money, string productName, string productCount, string description,string extension,  string orderSign, string notifyUrl);
 
- 	//android unity调用java层方法
 
- 	public static void callSdkApi (string apiName, params object[] args)
 
- 	{	
 
- 		using (AndroidJavaClass cls = new AndroidJavaClass("com.gsc.unityasdemo.GSCSdkCenter")) {
 
- 			cls.CallStatic (apiName, args);
 
- 		}
 
- 	}
 
- 	/**
 
- 	 * android 支付接口
 
- 	 * @param uid 用户的唯一标识(整型)
 
- 	 * @param username 用户名或者email(唯一)
 
- 	 * @param role 充值的角色信息
 
- 	 * @param serverId 区服号
 
- 	 * @param total_fee 充值金额
 
- 	 * @param game_money 游戏币,需要用充值金额*充值比率
 
- 	 * @param out_trade_no 充值订单号
 
- 	 * @param subject 充值主题
 
- 	 * @param body 充值描述
 
- 	 * @param extension_info 附加信息,会在服务器异步回调中原样传回
 
- 	 */
 
- 	public static void androidPay(long uid, string username, string role, string serverId,
 
- 	                       int total_fee, int game_money, string out_trade_no, string subject, string body, string extension_info, string notify_url, string order_sign)
 
- 	{
 
- 		#if UNITY_ANDROID
 
- 			callSdkApi ("pay", uid, username, role, serverId, total_fee, game_money, out_trade_no, subject, body, extension_info, notify_url, order_sign);
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * android获取设备指纹信息接口
 
- 	 */
 
- 	public static void androidFingerprint()
 
- 	{
 
- 		#if UNITY_ANDROID
 
- 			callSdkApi ("getFingerprint");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * android获取是否登录接口
 
- 	 */
 
- 	public static void androidCheckLogin()
 
- 	{
 
- 		#if UNITY_ANDROID
 
- 			callSdkApi ("checkLogin");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * android退出接口
 
- 	 */
 
- 	public static void androidExit ()
 
- 	{
 
- 		#if UNITY_ANDROID
 
- 			callSdkApi ("exit");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * iOS支付接口
 
- 	 */
 
- 	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)
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosPay(product_id, out_trade_no, money, subject, game_money, body, extension_info, order_sign, notify_url);
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * iOS获取sdk的版本接口
 
- 	 */
 
- 	public static void iOSSdkVersion()
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosGetSdkVersion();
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 初始化
 
- 	 */
 
- 	public static void init(string merchant_id, string app_id, string server_id, string app_key, string sandboxKey)
 
- 	{
 
- 		Debug.Log("init");
 
- 		#if UNITY_IOS
 
- 			__initIosSDK(merchant_id, app_id, server_id, app_key, sandboxKey);
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("init", merchant_id, app_id, server_id, app_key);
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 登录接口
 
- 	 */
 
- 	public static void login ()
 
- 	{
 
- 		#if UNITY_IOS
 
-             __iosLogin();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("login");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 通知区服接口
 
- 	 */
 
- 	public static void notifyZone(string server_id, string server_name, string role_id, string role_name)
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosNotifyZone(server_id, server_name, role_id, role_name);
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("notifyZone", server_id, server_name, role_id, role_name);
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 创角接口
 
- 	 */
 
- 	public static void createRole(string role_name, string role_id)
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosCreateRole(role_name, role_id);
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("createRole", role_id, role_name);
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 停止心跳接口
 
- 	 */
 
- 	public static void stopHeartbeat()
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosHeartbeatStop();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("stop");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 开始心跳接口
 
- 	 */
 
- 	public static void startHeartbeat()
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosHeartbeatStart();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("start");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 获取sdk类型接口
 
- 	 */
 
- 	public static void getSdkType()
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosGetSdkType();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("getSdkType");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 获取渠道号接口
 
- 	 */
 
- 	public static void getChannelId()
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosGetSdkChannel();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("getChannelId");
 
- 		#endif
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取是否实名认证接口
 
- 	 */
 
- 	public static void isRealNameAuth(){
 
- 		#if UNITY_IOS
 
- 			__iosIsRealnameAuth();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("isRealNameAuth");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 登出接口
 
- 	 */
 
- 	public static void logout()
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosLogout();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("logout");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 获取用户信息接口
 
- 	 */
 
- 	public static void getUserInfo(string accesskey)
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosUserInfo(accesskey);
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("getUserInfo");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 账号保护接口
 
- 	 */
 
- 	public static void accountProtect ()
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosAccountProtect();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("accountProtect");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 显示用户协议界面接口
 
- 	 */
 
- 	public static void showAgreementWithLicence ()
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosAgreementWithLicence();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("showAgreementWithLicence");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 显示隐私政策界面接口
 
- 	 */
 
- 	public static void showAgreementWithPrivacy ()
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosAgreementWithPrivacy();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("showAgreementWithPrivacy");
 
- 		#endif
 
- 	}
 
- 	/**
 
- 	 * 显示人机验证接口
 
- 	 */
 
- 	public static void showGeetestView ()
 
- 	{
 
- 		#if UNITY_IOS
 
- 			__iosGeetest();
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("showGeetestView");
 
- 		#endif
 
- 	}
 
- 	//测试
 
- 	public static void showToast(string content)
 
- 	{
 
- 		#if UNITY_IOS
 
- 		#elif UNITY_ANDROID
 
- 			callSdkApi ("showToast", content);
 
- 		#endif
 
- 	}
 
- }
 
 
  |