PottingMobileServicesManger.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class PottingMobileServicesManger : MonoBehaviour
  6. {
  7. // Singleton.
  8. public static PottingMobileServicesManger Instance { get; protected set; }
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. if (Instance == this)
  13. {
  14. }
  15. }
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. }
  20. void Awake()
  21. {
  22. if (Instance == null)
  23. Instance = this;
  24. if (transform.parent == null)
  25. DontDestroyOnLoad(gameObject);
  26. }
  27. //对于需要登录的接口,我们做了简单处理,用户登录的时候我们会保存用户的userId和token,
  28. //当我们查询到本地保存的userId或token为空时,给unity发以下消息并return,
  29. //游戏端需要提示用户登录或其他操作
  30. public void LoginStatus(string code)
  31. {
  32. Debug.Log("LoginStatus");
  33. var evt = LoginStatusEvent;
  34. if (evt != null) evt(code);
  35. }
  36. /**
  37. * 渠道下单接口,根据不同渠道需要的数据不同
  38. * 返回的数据结构不同,前端需要根据情况解析
  39. *
  40. */
  41. public void ChannelpayOrder(string data)
  42. {
  43. Debug.Log("ChannelpayOrder");
  44. var evt = ChannelpayOrderResponsesEvent;
  45. if (evt != null) evt(data);
  46. }
  47. /**
  48. * 获取当前游戏,渠道的最新版本
  49. * 返回结果无加密
  50. */
  51. public void ChannelpayGetAppVersion(string data)
  52. {
  53. Debug.Log("ChannelpayGetAppVersion");
  54. var evt = ChannelpayGetAppVersionResponsesEvent;
  55. if (evt != null) evt(data);
  56. }
  57. /**
  58. * 获取服务器配置
  59. * appver:如果不需要根据版本判断可以串0
  60. * lastver:每次全新获取传0
  61. */
  62. public void ConfigSync(string data)
  63. {
  64. Debug.Log("ConfigSync");
  65. var evt = ConfigSyncResponsesEvent;
  66. if (evt != null) evt(data);
  67. }
  68. /**
  69. * 兑换码兑换接口
  70. *
  71. */
  72. public void DedeemConsume(string data)
  73. {
  74. Debug.Log("DedeemConsume");
  75. var evt = DedeemConsumeResponsesEvent;
  76. if (evt != null) evt(data);
  77. }
  78. /**
  79. * 登录接口
  80. */
  81. public void UserLogin(string data)
  82. {
  83. Debug.Log("UserLogin");
  84. var evt = UserLoginResponsesEvent;
  85. if (evt != null) evt(data);
  86. }
  87. /**
  88. * 获取(提交)存档到服务器
  89. * 1.每次启动游戏优先获取存档
  90. * 2.当有需要更新的存档时提交服务器
  91. * 提交存档时服务器会默认覆盖以前的存档不会做其他判断
  92. * 请求需要签名,返回数据有加密
  93. */
  94. public void UserSync(string data)
  95. {
  96. Debug.Log("userSync");
  97. var evt = UserSyncResponsesEvent;
  98. if (evt != null) evt(data);
  99. }
  100. /**
  101. * 心跳检测,判断当前客户端登陆是否有效
  102. * 请求需要签名,返回数据无加密
  103. */
  104. public void UserHeartbeat(string data)
  105. {
  106. Debug.Log("UserHeartbeat");
  107. var evt = UserHeartbeatResponsesEvent;
  108. if (evt != null) evt(data);
  109. }
  110. /**
  111. * 用户下订接口,下单成功之后返回支付链接
  112. * -跳转支付页面
  113. *
  114. * @param goodsid 商品ID
  115. */
  116. public void UserOrder(string data)
  117. {
  118. Debug.Log("UserOrder");
  119. var evt = UserOrderResponsesEvent;
  120. if (evt != null) evt(data);
  121. }
  122. /**
  123. * 恢复购买,查看已完成的所有订单,以及消耗状态
  124. * 请求需要签名,返回结果有加密
  125. */
  126. public void UserResumepurchase(string data)
  127. {
  128. Debug.Log("UserResumepurchase");
  129. var evt = UserResumepurchaseResponsesEvent;
  130. if (evt != null) evt(data);
  131. }
  132. /**
  133. * 订单消耗
  134. * 请求需要签名,返回结果有加密
  135. */
  136. public void UserConsume(string data)
  137. {
  138. Debug.Log("UserConsume");
  139. var evt = UserConsumeResponsesEvent;
  140. if (evt != null) evt(data);
  141. }
  142. /**
  143. * 查询单个订单的状态
  144. * 用来处理非消耗性商品,判断订单是否支付完成
  145. * 返回结果有加密
  146. */
  147. public void UserQueryOrder(string data)
  148. {
  149. Debug.Log("UserQueryOrder");
  150. var evt = UserQueryOrderResponsesEvent;
  151. if (evt != null) evt(data);
  152. }
  153. /**
  154. * 提交用户分数
  155. * 返回用户排行榜信息,返回结果无加密
  156. */
  157. public void UserUploadScore(string data)
  158. {
  159. Debug.Log("UserUploadScore");
  160. var evt = UserUploadScoreResponsesEvent;
  161. if (evt != null) evt(data);
  162. }
  163. /**
  164. * 获取用户自己的排名
  165. */
  166. public void UserGetUserRank(string data)
  167. {
  168. Debug.Log("UserGetUserRank");
  169. var evt = UserGetUserRankResponsesEvent;
  170. if (evt != null) evt(data);
  171. }
  172. //用户支付结果
  173. public void PurchaseCallBack(string data) {
  174. Debug.Log("PurchaseCallBack");
  175. var evt = PurchaseCallBackEvent;
  176. if (evt != null) evt(data);
  177. }
  178. public void GetActivitiesWithChannel(string data) {
  179. var evt = GetActivitiesWithChannelkEvent;
  180. if (evt != null) evt(data);
  181. }
  182. public void GameAnoncementsWithChannel(string data)
  183. {
  184. var evt = GameAnoncementsWithChannelEvent;
  185. if (evt != null) evt(data);
  186. }
  187. public void RedeemConsume(string data)
  188. {
  189. var evt = RedeemConsumeEvent;
  190. if (evt != null) evt(data);
  191. }
  192. public void RedeemUserConsume(string data) {
  193. var evt = RedeemUserConsumeEvent;
  194. if (evt != null) evt(data);
  195. }
  196. public void feedBackSubmitComplected(string json)
  197. {
  198. var evt = MfeedBackSubmitEvent;
  199. if (evt != null) evt(json);
  200. }
  201. public void GoogleValidate(string json) {
  202. var evt = PayValidateEvent;
  203. if (evt != null) evt(json);
  204. }
  205. public void OverseaPayAppleValidate(string json) {
  206. var evt = PayValidateEvent;
  207. if (evt != null) evt(json);
  208. }
  209. public void GamekeyinfoUpload(string json) {
  210. var evt = GamekeyinfoUploadEvent;
  211. if (evt != null) evt(json);
  212. }
  213. public void Serverinfo(string json) {
  214. var evt = ServerinfoEvent;
  215. if (evt != null) evt(json);
  216. }
  217. /*
  218. * {
  219. "timestamp": 0
  220. }
  221. */
  222. public event Action<string> ServerinfoEvent;
  223. /// <summary>
  224. /// 支付校验回调
  225. /// </summary>
  226. public event Action<string> PayValidateEvent;
  227. /// <summary>
  228. /// 活动回调数据
  229. /// </summary>
  230. /*
  231. * 回调参数示例: 获取到活动数组,自行判断开始结束时间
  232. {
  233. "data" : [
  234. {
  235. "starttime" : 1591113600,
  236. "priceid" : "90647029-07d6-4abf-af59-b4cc04306500",
  237. "activityinfo" : "第十二次营救测试一个碎片情况",
  238. "price" : "1",
  239. "title" : "第十二次营救测试",
  240. "gameitems" : [
  241. {
  242. "iteminfo" : "{\"goodId\":\"2\",\"goodType\":\"6\"}",
  243. "itemname" : "玛丽安娜碎片",
  244. "num" : 1,
  245. "itemid" : "906475eb-9770-4131-af2d-0a6fe727576a"
  246. },
  247. {
  248. "iteminfo" : "{\"goodId\":\"10000\",\"goodType\":\"0\"}",
  249. "itemname" : "钻石",
  250. "num" : 100000,
  251. "itemid" : "906475eb-9842-4f7b-91de-580dad60f6d2"
  252. }
  253. ],
  254. "originalprice" : "5",
  255. "extradata" : "",
  256. "endtime" : 1591200000,
  257. "activityid" : "90b725fd-3faa-40ed-8880-d08e01a469f2"
  258. }
  259. ]
  260. }
  261. */
  262. public event Action<string> GetActivitiesWithChannelkEvent;
  263. /// <summary>
  264. /// 公告回调数据
  265. /// </summary>
  266. /*
  267. *{
  268. "data" : [
  269. {
  270. "anoncementinfo" : "tefdfsdfsdfds",
  271. "title" : "test",
  272. "channels" : "0,3",
  273. "anoncementid" : "90b756b9-38ae-4ae7-bdeb-bd1c330c630e",
  274. "gameitems" : [
  275. {
  276. "iteminfo" : "{\"goodId\":\"2\",\"goodType\":\"6\"}",
  277. "itemname" : "玛丽安娜碎片",
  278. "num" : 1,
  279. "itemid" : "906475eb-9770-4131-af2d-0a6fe727576a"
  280. }
  281. ]
  282. }
  283. ],
  284. "code" : 200
  285. }
  286. *
  287. */
  288. public event Action<string> GameAnoncementsWithChannelEvent;
  289. /// <summary>
  290. /// 渠道兑换码返回数据
  291. /// </summary>
  292. /*
  293. * {
  294. "data" : {
  295. "Goodsinfo" : "test",
  296. "Type" : 1,
  297. "Status" : 0
  298. },
  299. "code" : 200
  300. }
  301. */
  302. public event Action<string> RedeemConsumeEvent;
  303. /// <summary>
  304. /// 反馈接口回调
  305. /// </summary>
  306. /*
  307. * 成功:
  308. {
  309. "data" : {
  310. },
  311. "code" : 200
  312. }
  313. 失败:
  314. {
  315. "data" : {
  316. },
  317. "code" : 4004
  318. }
  319. */
  320. public event Action<string> MfeedBackSubmitEvent;
  321. public event Action<string> PurchaseCallBackEvent;
  322. public event Action<string> UserGetUserRankResponsesEvent;
  323. public event Action<string> UserUploadScoreResponsesEvent;
  324. public event Action<string> UserQueryOrderResponsesEvent;
  325. public event Action<string> UserConsumeResponsesEvent;
  326. public event Action<string> UserResumepurchaseResponsesEvent;
  327. public event Action<string> UserOrderResponsesEvent;
  328. public event Action<string> UserHeartbeatResponsesEvent;
  329. public event Action<string> UserSyncResponsesEvent;
  330. public event Action<string> UserLoginResponsesEvent;
  331. public event Action<string> DedeemConsumeResponsesEvent;
  332. public event Action<string> ChannelpayGetAppVersionResponsesEvent;
  333. public event Action<string> ChannelpayOrderResponsesEvent;
  334. public event Action<string> LoginStatusEvent;
  335. public event Action<string> ConfigSyncResponsesEvent;
  336. public event Action<string> RedeemUserConsumeEvent;
  337. /*
  338. * {
  339. "code" : 200
  340. }
  341. */
  342. public event Action<string> GamekeyinfoUploadEvent;
  343. }