You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

92 lines
2.9 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Text;
  7. using System.Reflection;
  8. using ETModel.com.commsdk.unity3d;
  9. using ETModel;
  10. namespace ETHotfix
  11. {
  12. namespace com.commsdk.unity3d
  13. {
  14. /// <summary>
  15. ///公用的原生sdk
  16. /// </summary>
  17. public class CommSDKComponent : MonoBehaviour
  18. {
  19. private int WeReqID;
  20. private CommSDKImpl commSdkUtils;
  21. public EventWechatHandler responseHandler;
  22. public void Init()
  23. {
  24. if (Application.platform == RuntimePlatform.Android)
  25. {
  26. Debug.Log("GameObject.name = " + gameObject.name);
  27. commSdkUtils = new AndroidImpl(gameObject.name, "_Callback");
  28. }
  29. }
  30. /// <summary>
  31. /// callback the specified data.
  32. /// </summary>
  33. /// <param name='data'>
  34. /// Data.
  35. /// </param>
  36. private void _Callback(string data)
  37. {
  38. if (data == null)
  39. {
  40. Debug.Log("OnWechatLogin DataIsNull" + data + "DataIsNull Data");
  41. return;
  42. }
  43. Hashtable res = (Hashtable)MiniJSON.jsonDecode(data);
  44. if (res == null || res.Count <= 0)
  45. {
  46. Debug.Log("OnWechatLogin ResIsNull" + data + "ResIsNull Data");
  47. return;
  48. }
  49. int status = Convert.ToInt32(res["status"]);
  50. int reqID = Convert.ToInt32(res["reqID"]);
  51. int action = Convert.ToInt32(res["action"]);
  52. Hashtable resp = null;
  53. switch ((RespState)status)
  54. {
  55. case RespState.Success:
  56. case RespState.Fail:
  57. resp = (Hashtable)res["res"];
  58. break;
  59. case RespState.Cancel:
  60. break;
  61. }
  62. if (resp == null)
  63. {
  64. Debug.Log("OnWechatLogin RespIsNull" + data + "RespIsNull");
  65. }
  66. if (null != responseHandler)
  67. {
  68. responseHandler(reqID, (ActionType)action, (RespState)status, resp);
  69. }
  70. }
  71. public int Authorize(int type)
  72. {
  73. WeReqID++;
  74. commSdkUtils.Authorize(type, WeReqID);
  75. return WeReqID;
  76. }
  77. /// <summary>
  78. /// Event result listener.
  79. /// </summary>
  80. public delegate void EventWechatHandler(int reqID, ActionType type, RespState state, Hashtable data);
  81. }
  82. }
  83. }