| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 | 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<ShareSDK>();            ssdk.authHandler = OnAuthResultHandler;            ssdk.shareHandler = OnShareResultHandler;            ssdk.showUserHandler = OnGetUserInfoResultHandler;            ssdk.getFriendsHandler = OnGetFriendsResultHandler;            ssdk.followFriendHandler = OnFollowFriendResultHandler;            ssdk.clientValidForAndroidHandler = OnIsClientValidForAndroidHandler;            mobsdk = mainCameraObject.GetComponent<MobSDK>();        }        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);        /// <summary>        /// 授权回调        /// </summary>        /// <param name="reqID"></param>        /// <param name="state"></param>        /// <param name="type"></param>        /// <param name="result"></param>        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);        }        /// <summary>        /// 指定获取用户信息的回调-->应该是调用 ssdk.GetUserInfo(PlatformType.SinaWeibo); 之后得到这个回调        /// </summary>        /// <param name="reqID"></param>        /// <param name="state"></param>        /// <param name="type"></param>        /// <param name="result"></param>        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);        }        /// <summary>        /// 应该是分享回调        /// </summary>        /// <param name="reqID"></param>        /// <param name="state"></param>        /// <param name="type"></param>        /// <param name="result"></param>        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);        }        /// <summary>        /// 获取好友列表结果        /// </summary>        /// <param name="reqID"></param>        /// <param name="state"></param>        /// <param name="type"></param>        /// <param name="result"></param>        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);        }        /// <summary>        /// 关注好友回调        /// </summary>        /// <param name="reqID"></param>        /// <param name="state"></param>        /// <param name="type"></param>        /// <param name="result"></param>        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);        }        /// <summary>        /// 关于客户端对Android处理程序有效吗        /// </summary>        /// <param name="reqID"></param>        /// <param name="state"></param>        /// <param name="type"></param>        /// <param name="result"></param>        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);        }    }}
 |