AbShareSDKHandler.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using System.Collections;
  2. using UnityEngine;
  3. namespace cn.sharesdk.unity3d
  4. {
  5. public abstract class AbShareSDKHandler : MonoBehaviour
  6. {
  7. public ShareSDK ssdk;
  8. public MobSDK mobsdk;
  9. void Start()
  10. {
  11. GameObject mainCameraObject = GameObject.Find("GameLauncher");
  12. ssdk = mainCameraObject.GetComponent<ShareSDK>();
  13. ssdk.authHandler = OnAuthResultHandler;
  14. ssdk.shareHandler = OnShareResultHandler;
  15. ssdk.showUserHandler = OnGetUserInfoResultHandler;
  16. ssdk.getFriendsHandler = OnGetFriendsResultHandler;
  17. ssdk.followFriendHandler = OnFollowFriendResultHandler;
  18. ssdk.clientValidForAndroidHandler = OnIsClientValidForAndroidHandler;
  19. mobsdk = mainCameraObject.GetComponent<MobSDK>();
  20. }
  21. public abstract void OnAuthResult(int reqID, ResponseState state, PlatformType type, Hashtable result);
  22. public abstract void OnGetUserInfoResult(int reqID, ResponseState state, PlatformType type,
  23. Hashtable result);
  24. public abstract void OnShareResult(int reqID, ResponseState state, PlatformType type, Hashtable result);
  25. public abstract void OnGetFriendsResult(int reqID, ResponseState state, PlatformType type,
  26. Hashtable result);
  27. public abstract void OnFollowFriendResult(int reqID, ResponseState state, PlatformType type,
  28. Hashtable result);
  29. public abstract void OnIsClientValidForAndroidResult(int reqID, ResponseState state, PlatformType type,
  30. Hashtable result);
  31. /// <summary>
  32. /// 授权回调
  33. /// </summary>
  34. /// <param name="reqID"></param>
  35. /// <param name="state"></param>
  36. /// <param name="type"></param>
  37. /// <param name="result"></param>
  38. void OnAuthResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
  39. {
  40. string message = "";
  41. if (state == ResponseState.Success)
  42. {
  43. if (result != null && result.Count > 0)
  44. {
  45. Debug.Log("authorize success !" + "Platform :" + type + "result:" + MiniJSON.jsonEncode(result));
  46. }
  47. else
  48. {
  49. Debug.Log("authorize success !" + "Platform :" + type);
  50. }
  51. }
  52. else if (state == ResponseState.Fail)
  53. {
  54. #if UNITY_ANDROID
  55. Debug.Log("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
  56. #elif UNITY_IPHONE
  57. Debug.Log ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]);
  58. #endif
  59. }
  60. else if (state == ResponseState.Cancel)
  61. {
  62. Debug.Log("cancel !");
  63. }
  64. OnAuthResult(reqID, state, type, result);
  65. }
  66. /// <summary>
  67. /// 指定获取用户信息的回调-->应该是调用 ssdk.GetUserInfo(PlatformType.SinaWeibo); 之后得到这个回调
  68. /// </summary>
  69. /// <param name="reqID"></param>
  70. /// <param name="state"></param>
  71. /// <param name="type"></param>
  72. /// <param name="result"></param>
  73. void OnGetUserInfoResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
  74. {
  75. if (state == ResponseState.Success)
  76. {
  77. Debug.Log("get user info result :");
  78. Debug.Log(MiniJSON.jsonEncode(result));
  79. Debug.Log("AuthInfo:" + MiniJSON.jsonEncode(ssdk.GetAuthInfo(type)));
  80. Debug.Log("Get userInfo success !Platform :" + type);
  81. }
  82. else if (state == ResponseState.Fail)
  83. {
  84. #if UNITY_ANDROID
  85. Debug.Log("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
  86. #elif UNITY_IPHONE
  87. Debug.Log ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]);
  88. #endif
  89. }
  90. else if (state == ResponseState.Cancel)
  91. {
  92. Debug.Log("cancel !");
  93. }
  94. OnGetUserInfoResult(reqID, state, type, result);
  95. }
  96. /// <summary>
  97. /// 应该是分享回调
  98. /// </summary>
  99. /// <param name="reqID"></param>
  100. /// <param name="state"></param>
  101. /// <param name="type"></param>
  102. /// <param name="result"></param>
  103. void OnShareResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
  104. {
  105. if (state == ResponseState.Success)
  106. {
  107. Debug.Log("share successfully - share result :");
  108. Debug.Log(MiniJSON.jsonEncode(result));
  109. }
  110. else if (state == ResponseState.Fail)
  111. {
  112. #if UNITY_ANDROID
  113. Debug.Log("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
  114. #elif UNITY_IPHONE
  115. Debug.Log ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]);
  116. #endif
  117. }
  118. else if (state == ResponseState.Cancel)
  119. {
  120. Debug.Log("cancel !");
  121. }
  122. OnShareResult(reqID, state, type, result);
  123. }
  124. /// <summary>
  125. /// 获取好友列表结果
  126. /// </summary>
  127. /// <param name="reqID"></param>
  128. /// <param name="state"></param>
  129. /// <param name="type"></param>
  130. /// <param name="result"></param>
  131. void OnGetFriendsResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
  132. {
  133. if (state == ResponseState.Success)
  134. {
  135. Debug.Log("get friend list result :");
  136. Debug.Log(MiniJSON.jsonEncode(result));
  137. }
  138. else if (state == ResponseState.Fail)
  139. {
  140. #if UNITY_ANDROID
  141. Debug.Log("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
  142. #elif UNITY_IPHONE
  143. Debug.Log ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]);
  144. #endif
  145. }
  146. else if (state == ResponseState.Cancel)
  147. {
  148. Debug.Log("cancel !");
  149. }
  150. OnGetFriendsResult(reqID, state, type, result);
  151. }
  152. /// <summary>
  153. /// 关注好友回调
  154. /// </summary>
  155. /// <param name="reqID"></param>
  156. /// <param name="state"></param>
  157. /// <param name="type"></param>
  158. /// <param name="result"></param>
  159. void OnFollowFriendResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
  160. {
  161. if (state == ResponseState.Success)
  162. {
  163. Debug.Log("Follow friend successfully !");
  164. }
  165. else if (state == ResponseState.Fail)
  166. {
  167. #if UNITY_ANDROID
  168. Debug.Log("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
  169. #elif UNITY_IPHONE
  170. Debug.Log ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]);
  171. #endif
  172. }
  173. else if (state == ResponseState.Cancel)
  174. {
  175. Debug.Log("cancel !");
  176. }
  177. OnFollowFriendResult(reqID, state, type, result);
  178. }
  179. /// <summary>
  180. /// 关于客户端对Android处理程序有效吗
  181. /// </summary>
  182. /// <param name="reqID"></param>
  183. /// <param name="state"></param>
  184. /// <param name="type"></param>
  185. /// <param name="result"></param>
  186. void OnIsClientValidForAndroidHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
  187. {
  188. if (state == ResponseState.Success)
  189. {
  190. Debug.Log("IsClientValidForAndroid successfully !");
  191. Debug.Log("IsClientValidForAndroid:" + MiniJSON.jsonEncode(MiniJSON.jsonEncode(result)));
  192. }
  193. else if (state == ResponseState.Fail)
  194. {
  195. Debug.Log("IsClientValidForAndroid Fail !");
  196. }
  197. else if (state == ResponseState.Cancel)
  198. {
  199. Debug.Log("cancel !");
  200. }
  201. OnIsClientValidForAndroidResult(reqID, state, type, result);
  202. }
  203. }
  204. }