using System.Collections; using UnityEngine; namespace cn.sharesdk.unity3d { public abstract class AbShareSDKHandler : MonoBehaviour { public ShareSDK ssdk; public MobSDK mobsdk; void Start() { GameObject mainCameraObject = GameObject.Find("GameLauncher"); ssdk = mainCameraObject.GetComponent(); ssdk.authHandler = OnAuthResultHandler; ssdk.shareHandler = OnShareResultHandler; ssdk.showUserHandler = OnGetUserInfoResultHandler; ssdk.getFriendsHandler = OnGetFriendsResultHandler; ssdk.followFriendHandler = OnFollowFriendResultHandler; ssdk.clientValidForAndroidHandler = OnIsClientValidForAndroidHandler; mobsdk = mainCameraObject.GetComponent(); } public abstract void OnAuthResult(int reqID, ResponseState state, PlatformType type, Hashtable result); public abstract void OnGetUserInfoResult(int reqID, ResponseState state, PlatformType type, Hashtable result); public abstract void OnShareResult(int reqID, ResponseState state, PlatformType type, Hashtable result); public abstract void OnGetFriendsResult(int reqID, ResponseState state, PlatformType type, Hashtable result); public abstract void OnFollowFriendResult(int reqID, ResponseState state, PlatformType type, Hashtable result); public abstract void OnIsClientValidForAndroidResult(int reqID, ResponseState state, PlatformType type, Hashtable result); /// /// 授权回调 /// /// /// /// /// void OnAuthResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result) { string message = ""; if (state == ResponseState.Success) { if (result != null && result.Count > 0) { Debug.Log("authorize success !" + "Platform :" + type + "result:" + MiniJSON.jsonEncode(result)); } else { Debug.Log("authorize success !" + "Platform :" + type); } } else if (state == ResponseState.Fail) { #if UNITY_ANDROID Debug.Log("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]); #elif UNITY_IPHONE Debug.Log ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]); #endif } else if (state == ResponseState.Cancel) { Debug.Log("cancel !"); } OnAuthResult(reqID, state, type, result); } /// /// 指定获取用户信息的回调-->应该是调用 ssdk.GetUserInfo(PlatformType.SinaWeibo); 之后得到这个回调 /// /// /// /// /// void OnGetUserInfoResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result) { if (state == ResponseState.Success) { Debug.Log("get user info result :"); Debug.Log(MiniJSON.jsonEncode(result)); Debug.Log("AuthInfo:" + MiniJSON.jsonEncode(ssdk.GetAuthInfo(type))); Debug.Log("Get userInfo success !Platform :" + type); } else if (state == ResponseState.Fail) { #if UNITY_ANDROID Debug.Log("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]); #elif UNITY_IPHONE Debug.Log ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]); #endif } else if (state == ResponseState.Cancel) { Debug.Log("cancel !"); } OnGetUserInfoResult(reqID, state, type, result); } /// /// 应该是分享回调 /// /// /// /// /// void OnShareResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result) { if (state == ResponseState.Success) { Debug.Log("share successfully - share result :"); Debug.Log(MiniJSON.jsonEncode(result)); } else if (state == ResponseState.Fail) { #if UNITY_ANDROID Debug.Log("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]); #elif UNITY_IPHONE Debug.Log ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]); #endif } else if (state == ResponseState.Cancel) { Debug.Log("cancel !"); } OnShareResult(reqID, state, type, result); } /// /// 获取好友列表结果 /// /// /// /// /// void OnGetFriendsResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result) { if (state == ResponseState.Success) { Debug.Log("get friend list result :"); Debug.Log(MiniJSON.jsonEncode(result)); } else if (state == ResponseState.Fail) { #if UNITY_ANDROID Debug.Log("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]); #elif UNITY_IPHONE Debug.Log ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]); #endif } else if (state == ResponseState.Cancel) { Debug.Log("cancel !"); } OnGetFriendsResult(reqID, state, type, result); } /// /// 关注好友回调 /// /// /// /// /// void OnFollowFriendResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result) { if (state == ResponseState.Success) { Debug.Log("Follow friend successfully !"); } else if (state == ResponseState.Fail) { #if UNITY_ANDROID Debug.Log("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]); #elif UNITY_IPHONE Debug.Log ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]); #endif } else if (state == ResponseState.Cancel) { Debug.Log("cancel !"); } OnFollowFriendResult(reqID, state, type, result); } /// /// 关于客户端对Android处理程序有效吗 /// /// /// /// /// void OnIsClientValidForAndroidHandler(int reqID, ResponseState state, PlatformType type, Hashtable result) { if (state == ResponseState.Success) { Debug.Log("IsClientValidForAndroid successfully !"); Debug.Log("IsClientValidForAndroid:" + MiniJSON.jsonEncode(MiniJSON.jsonEncode(result))); } else if (state == ResponseState.Fail) { Debug.Log("IsClientValidForAndroid Fail !"); } else if (state == ResponseState.Cancel) { Debug.Log("cancel !"); } OnIsClientValidForAndroidResult(reqID, state, type, result); } } }