HttpManager.cs 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.Events;
  5. using System;
  6. using System.IO;
  7. using System.Net;
  8. using System.Xml;
  9. using System.Text;
  10. using System.Linq;
  11. using System.Net.Mail;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using Random = UnityEngine.Random;
  15. public class MailItemLabel
  16. {
  17. public static string Title = "Title";
  18. public static string Icon1 = "Icon1";
  19. public static string Icon2 = "Icon2";
  20. public static string Icon3 = "Icon3";
  21. }
  22. public class MyCredentials : ICredentialsByHost
  23. {
  24. public NetworkCredential NetworkCredential;
  25. public NetworkCredential GetCredential(string host, int port, string authType)
  26. {
  27. return NetworkCredential.GetCredential(new Uri("http://" + host + ":" + port), authType);
  28. }
  29. public MyCredentials(string username, string password)
  30. {
  31. NetworkCredential = new NetworkCredential(username, password);
  32. }
  33. }
  34. public enum CommentType
  35. {
  36. Garden = 0,
  37. }
  38. public class HttpManager : Regist
  39. {
  40. public class MailReward
  41. {
  42. public string ID;
  43. public string Key;
  44. public string Value;
  45. public MailReward(string id, string key, string value)
  46. {
  47. ID = id;
  48. Key = key;
  49. Value = value;
  50. }
  51. }
  52. #region Config
  53. public static bool IsConnect
  54. {
  55. get
  56. {
  57. if (isConnect)
  58. {
  59. return true;
  60. }
  61. else
  62. {
  63. return TutorialManager.ConnectExempt;
  64. }
  65. }
  66. set { isConnect = value; }
  67. }
  68. public static bool isConnect;
  69. public static bool BuyPackLimitFlag
  70. {
  71. get { return buyPackLimitFlag; }
  72. set
  73. {
  74. buyPackLimitFlag = value;
  75. foreach (var kv in Manager.SkillDictionary)
  76. {
  77. if (kv.Value is Pack)
  78. {
  79. ((Pack) kv.Value).SetActive();
  80. }
  81. }
  82. }
  83. }
  84. public static bool buyPackLimitFlag;
  85. public static int MaxReconnectAmt = 4;
  86. public static int ReconnectCounter;
  87. public static float ReconnectTime = 2f;
  88. public static float ReconnectTimeTimer;
  89. public static int PraiseAmt;
  90. public static bool IsRankDataReady;
  91. public static List<JsonData> RankDatas;
  92. public static int AnnounceIndex = -1;
  93. public static bool IsAnnounceReady;
  94. public static string AnnounceContent;
  95. public static Sprite AnnounceSpite;
  96. public static int ReplayVersion;
  97. public static bool Inited;
  98. public static bool FirstTimeConnectFlag = true;
  99. public static string ID = PlayerConfigLabel.DefaultID;
  100. public static string SerialNumber = PlayerConfigLabel.DefaultSerialNumber;
  101. public static string ReportIssueContent;
  102. public static JsonData LoginCallbackData;
  103. public static DateTime CurrentDateTime = DateTime.Now;
  104. public static string MailXmlStr;
  105. public static List<MailReward> MailRewardList = new List<MailReward>();
  106. public static string BaseURL = "https://garden.dashgame.com/index.php/home";
  107. public static string NewBaseURL = "https://garden.dashgame.com/index.php/newhome";
  108. public static string NicknameURL = NewBaseURL + "/user/nickname";
  109. public static string RankURL = NewBaseURL + "/user/look";
  110. public static string PraiseURL= NewBaseURL + "/praise/click";
  111. public static string TargetURL= NewBaseURL + "/praise/target";
  112. public static string AddCommentURL= NewBaseURL + "/comment/comment";
  113. public static string GetCommentURL= NewBaseURL + "/comment/index";
  114. public static string IndexURL= NewBaseURL + "/index/index";
  115. public static string GetProductIDURL= NewBaseURL + "/pay/pay";
  116. public static string LoginURL= NewBaseURL + "/user/login";
  117. public static string SaveURL= NewBaseURL + "/user/save";
  118. public static string OtherURL= NewBaseURL + "/user/other";
  119. public static string DownloadURL= NewBaseURL + "/user/load";
  120. public static string RandomURL= NewBaseURL + "/user/rand";
  121. public static string ThanksGiftInfoURL= NewBaseURL + "/index/gift";
  122. public static string ReportMailAddress= "bug@dashgame.com";
  123. #endregion
  124. public void Awake()
  125. {
  126. }
  127. public void Update()
  128. {
  129. if (!Manager.Inited && !Inited)
  130. {
  131. ReconnectTimeTimer += Time.deltaTime;
  132. if (ReconnectTimeTimer >= ReconnectTime)
  133. {
  134. ReconnectTimeTimer = 0;
  135. ReconnectCounter++;
  136. if (ReconnectCounter > MaxReconnectAmt)
  137. {
  138. Inited = true;
  139. Manager.FirstTimeLoginCallback(new JsonData());
  140. }
  141. else
  142. {
  143. Login(Manager.FirstTimeLoginCallback);
  144. GetAlipayFlag();
  145. }
  146. }
  147. }
  148. }
  149. public override bool InitAtOnce()
  150. {
  151. if (base.InitAtOnce())
  152. {
  153. return true;
  154. }
  155. enabled = true;
  156. return false;
  157. }
  158. public override void FirstInit()
  159. {
  160. ReplayVersion = ConfigManager.GetIntFormConfig(PlayerConfigLabel.ReplayVersion);
  161. }
  162. public static void SetNickName(string nickname, Action succeedCallback, Action<string> failCallback)
  163. {
  164. URLRequestData urlData = new URLRequestData();
  165. urlData.Add("u", SerialNumber);
  166. urlData.Add("n", nickname);
  167. URLRequest.CreateStrURLRequest
  168. (
  169. true,
  170. NicknameURL,
  171. urlData,
  172. data =>
  173. {
  174. if (data == "{\"error\":0}")
  175. {
  176. succeedCallback.Invoke();
  177. }
  178. else if (data.Contains("Could not resolve host"))
  179. {
  180. failCallback.Invoke(Language.GetStr(LanguageLabel.UI__Fg_Lab3));
  181. }
  182. else
  183. {
  184. failCallback.Invoke(Language.GetStr(LanguageLabel.UI__T_RepeatName));
  185. }
  186. },
  187. URLRequest.Method.POST
  188. );
  189. }
  190. public static void GetRankData()
  191. {
  192. URLRequestData urlData = new URLRequestData();
  193. URLRequest.CreateStrURLRequest
  194. (
  195. false,
  196. RankURL,
  197. urlData,
  198. data =>
  199. {
  200. string str = "{\"l\":" + data.Substring(1) + "}";
  201. JsonData jsondata;
  202. try
  203. {
  204. jsondata = JsonMapper.ToObject(str);
  205. }
  206. catch (Exception)
  207. {
  208. jsondata = new JsonData();
  209. jsondata["error"] = 0;
  210. }
  211. GetRankDataCallback(jsondata);
  212. }
  213. );
  214. }
  215. public static void GetRankDataCallback(JsonData jsonData)
  216. {
  217. if (jsonData.Inst_Object.ContainsKey("l"))
  218. {
  219. RankDatas = new List<JsonData>();
  220. for (int i = 0; i < jsonData["l"].Count; i++)
  221. {
  222. RankDatas.Add(jsonData["l"][i]);
  223. }
  224. IsRankDataReady = true;
  225. SocialManager.InitRankPanel();
  226. }
  227. }
  228. public static void GetAnnounceData()
  229. {
  230. GetUrlAddress
  231. (
  232. data =>
  233. {
  234. URLRequestData urlData = new URLRequestData();
  235. URLRequest.CreateStrURLRequest
  236. (
  237. true,
  238. data["l"][3]["val"].ToString(),
  239. urlData,
  240. notificationXml =>
  241. {
  242. GetAnnounceDataCallback(notificationXml);
  243. }
  244. );
  245. }
  246. );
  247. }
  248. public static void GetAnnounceDataCallback(string xml)
  249. {
  250. XmlNode rootNode;
  251. XmlDocument document = new XmlDocument();
  252. try
  253. {
  254. document.LoadXml(xml);
  255. rootNode = document.SelectSingleNode("announce");
  256. AnnounceIndex = int.Parse(rootNode.SelectSingleNode("version").InnerText);
  257. XmlNodeList nodeList = rootNode.SelectNodes(ConfigLabel.ChildNode);
  258. List<string> urlList = new List<string>();
  259. for (int i = 0; i < nodeList.Count; i++)
  260. {
  261. DecodeAnnounceData(nodeList[i], urlList);
  262. }
  263. Auxiliary.Instance.StartCoroutine(PullAnnounceSprite(urlList, PullAnnounceSpriteCallback));
  264. }
  265. catch (Exception e)
  266. {
  267. Debug.LogWarning(e);
  268. }
  269. }
  270. public static void DecodeAnnounceData(XmlNode node, List<string> urlList)
  271. {
  272. XmlNodeList nodeList = node.SelectNodes("title");
  273. for (int i = 0; i < nodeList.Count; i++)
  274. {
  275. AnnounceManager.AddContent(false, nodeList[i].Attributes[0].Value, nodeList[i].InnerText, TextAnchor.MiddleLeft);
  276. }
  277. AnnounceManager.AddContent(false, "null", node.SelectSingleNode("date").InnerText, TextAnchor.MiddleLeft);
  278. nodeList = node.SelectSingleNode("content").ChildNodes;
  279. for (int i = 0; i < nodeList.Count; i++)
  280. {
  281. if (nodeList[i].Name == "text")
  282. {
  283. AnnounceManager.AddContent(false, nodeList[i].Attributes[0].Value, nodeList[i].InnerText, TextAnchor.MiddleLeft);
  284. }
  285. else if (nodeList[i].Name == "image")
  286. {
  287. urlList.UniqueAdd(nodeList[i].InnerText);
  288. AnnounceManager.AddContent(true, "null", $"<({Path.GetFileNameWithoutExtension(nodeList[i].InnerText)})>", TextAnchor.MiddleCenter);
  289. }
  290. }
  291. AnnounceManager.AddContent(false, "null", "", TextAnchor.MiddleLeft);
  292. }
  293. public static IEnumerator PullAnnounceSprite(List<string> urlList, Action<List<WWW>> callback)
  294. {
  295. List<WWW> wwwList = new List<WWW>();
  296. for (int i = 0; i < urlList.Count; i++)
  297. {
  298. wwwList.Add(new WWW(urlList[i]));
  299. }
  300. for (int i = 0; i < wwwList.Count; i++)
  301. {
  302. yield return wwwList[i];
  303. }
  304. callback(wwwList);
  305. }
  306. public static void PullAnnounceSpriteCallback(List<WWW> wwwList)
  307. {
  308. List<Texture2D> textureList = new List<Texture2D>();
  309. List<SpriteInfo> spriteInfoList = new List<SpriteInfo>();
  310. for (int i = 0; i < wwwList.Count; i++)
  311. {
  312. textureList.Add(wwwList[i].texture);
  313. SpriteInfo spriteInfo = new SpriteInfo();
  314. spriteInfo.Name = Path.GetFileNameWithoutExtension(wwwList[i].url);
  315. spriteInfoList.Add(spriteInfo);
  316. }
  317. Texture2D atlas = new Texture2D(2048, 2048);
  318. Rect[] rects = atlas.PackTextures(textureList.ToArray(), 1);
  319. Sprite sprite = Sprite.Create(atlas, new Rect(0, 0, atlas.width, atlas.height), new Vector2(0.5f, 0.5f));
  320. for (int i = 0; i < spriteInfoList.Count; i++)
  321. {
  322. spriteInfoList[i].Width = textureList[i].width;
  323. spriteInfoList[i].Height = textureList[i].height;
  324. spriteInfoList[i].UvList = new List<Vector2>()
  325. {
  326. new Vector2(rects[i].xMin, rects[i].yMax),
  327. new Vector2(rects[i].xMax, rects[i].yMax),
  328. new Vector2(rects[i].xMax, rects[i].yMin),
  329. new Vector2(rects[i].xMin, rects[i].yMin),
  330. };
  331. SpriteAsset.SpriteInfoDic.Add(spriteInfoList[i].Name, spriteInfoList[i]);
  332. }
  333. AnnounceSpite = sprite;
  334. IsAnnounceReady = true;
  335. if (Initializer.Inited)
  336. {
  337. ResourceManager.Get(ObjectLabel.C_Notify).TweenForCG();
  338. }
  339. }
  340. public static void Praise(string sendID, string receiveID)
  341. {
  342. if (receiveID == null)
  343. {
  344. return;
  345. }
  346. URLRequestData urlData = new URLRequestData();
  347. urlData.Add("u", sendID);
  348. urlData.Add("t", receiveID);
  349. URLRequest.CreateStrURLRequest(true, PraiseURL, urlData, (data)=> {}, URLRequest.Method.POST);
  350. }
  351. public static void CheckIsPraised(string userID, string targetID, Action<JsonData> callback)
  352. {
  353. URLRequestData urlData = new URLRequestData();
  354. urlData.Add("u", userID);
  355. urlData.Add("t", targetID);
  356. URLRequest.CreateURLRequest(true, TargetURL, urlData, data => callback(data), URLRequest.Method.POST);
  357. }
  358. public static void AddComment(string sendID, string receiveID, string content, CommentType type)
  359. {
  360. if (string.IsNullOrEmpty(sendID) || string.IsNullOrEmpty(receiveID))
  361. {
  362. return;
  363. }
  364. if (sendID.ToLower() == PlayerConfigLabel.DefaultID.ToLower() || receiveID.ToLower() == PlayerConfigLabel.DefaultID.ToLower())
  365. {
  366. return;
  367. }
  368. URLRequestData urlData = new URLRequestData();
  369. urlData.Add("c", sendID);
  370. urlData.Add("u", receiveID);
  371. urlData.Add("i", content);
  372. urlData.Add("t", type.GetHashCode());
  373. URLRequest.CreateStrURLRequest
  374. (
  375. true,
  376. AddCommentURL,
  377. urlData,
  378. data =>
  379. {
  380. if (data == "{\"error\":0}")
  381. {
  382. Bubble.Show(Language.GetStr(LanguageLabel.UI__Q_CommentDone));
  383. SocialManager.UpdateCommentPage(false);
  384. }
  385. else
  386. {
  387. Bubble.Show(Language.GetStr(LanguageLabel.UI__Q_CommentFail));
  388. }
  389. },
  390. URLRequest.Method.POST
  391. );
  392. }
  393. public static void GetComment(string id, string page, CommentType type, Action<JsonData> callback)
  394. {
  395. JsonData defaultData = new JsonData();
  396. defaultData["error"] = 0;
  397. if (string.IsNullOrEmpty(id))
  398. {
  399. callback.Invoke(defaultData);
  400. return;
  401. }
  402. if (id.ToLower() == PlayerConfigLabel.DefaultID.ToLower())
  403. {
  404. callback.Invoke(defaultData);
  405. return;
  406. }
  407. URLRequestData urlData = new URLRequestData();
  408. urlData.Add("u", id);
  409. urlData.Add("p", page);
  410. urlData.Add("t", type.GetHashCode());
  411. URLRequest.CreateURLRequest(true, GetCommentURL, urlData, data => { callback(data);}, URLRequest.Method.POST);
  412. }
  413. public static void GetUrlAddress(Action<JsonData> callback)
  414. {
  415. URLRequestData urlData = new URLRequestData();
  416. URLRequest.CreateURLRequest
  417. (
  418. true,
  419. IndexURL,
  420. urlData,
  421. data =>
  422. {
  423. if (data.Inst_Object.ContainsKey("error"))
  424. {
  425. if (ConfigManager.configDocument != null)
  426. {
  427. if (Application.platform == RuntimePlatform.Android)
  428. {
  429. BuyPackLimitFlag = true;
  430. }
  431. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  432. {
  433. BuyPackLimitFlag = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.PackLock);
  434. }
  435. }
  436. }
  437. else
  438. {
  439. callback(data);
  440. }
  441. }
  442. );
  443. }
  444. public static void GetMailAwardData()
  445. {
  446. //MailXml = "<mail>" +
  447. // "<OneTimeReward>" +
  448. // "<id>4</id>" +
  449. // "<start>2017-08-18 12:12:12</start>" +
  450. // "<end>2017-09-1 11:30:12</end>" +
  451. // "<reward>" +
  452. // "<coin>1000</coin>" +
  453. // "<diamond>10</diamond>" +
  454. // "</reward>" +
  455. // "<targets>" +
  456. // "<id>90arbl</id>" +
  457. // "</targets>" +
  458. // "</OneTimeReward>" +
  459. // "<OneTimeReward>" +
  460. // "<id>3</id>" +
  461. // "<start>2017-08-21 12:12:12</start>" +
  462. // "<end>2017-09-01 18:12:12</end>" +
  463. // "<reward>" +
  464. // "<coin>10000</coin>" +
  465. // "<diamond>100</diamond>" +
  466. // "</reward>" +
  467. // "<targets>" +
  468. // "<id>90arbl</id>" +
  469. // "</targets>" +
  470. // "</OneTimeReward>" +
  471. // "</mail>";
  472. GetUrlAddress
  473. (
  474. data =>
  475. {
  476. URLRequestData urlData = new URLRequestData();
  477. URLRequest.CreateStrURLRequest
  478. (
  479. true,
  480. data["l"][1]["val"].ToJson().Trim('"'),
  481. urlData,
  482. mailXml =>
  483. {
  484. MailXmlStr = mailXml;
  485. }
  486. );
  487. }
  488. );
  489. }
  490. public static void GetAllMailReward()
  491. {
  492. for (int i = 0; i < MailRewardList.Count; i++)
  493. {
  494. GetMailReward(MailRewardList[i]);
  495. }
  496. }
  497. public static void GetMailReward(MailReward mailReward)
  498. {
  499. ConfigManager.SaveStringToConfig(PlayerConfigLabel.OneTimeReward, $"{ConfigManager.GetStringFormConfig(PlayerConfigLabel.OneTimeReward)} {mailReward.ID}".Trim(' '));
  500. Transform mailItem = ResourceManager.Get(ResourceLabel.MailItem, Folder.UI, false, ResourceManager.Get(ObjectLabel.Bd_Grid), new Vector3(), ObjType.MailItem);
  501. Dictionary<string, Transform> childDictionary = new Dictionary<string, Transform>();
  502. Auxiliary.CompileDic(mailItem, childDictionary);
  503. Text lab = childDictionary[MailItemLabel.Title].GetComponent<Text>();
  504. Image Icon1 = childDictionary[MailItemLabel.Icon1].GetComponent<Image>();
  505. Image Icon2 = childDictionary[MailItemLabel.Icon2].GetComponent<Image>();
  506. Image Icon3 = childDictionary[MailItemLabel.Icon3].GetComponent<Image>();
  507. if (mailReward.Key == "pack")
  508. {
  509. SkillRoot skillRoot;
  510. if (Manager.SkillDictionary.TryGetValue($"{SkillConfigLabel.Pack}{mailReward.Value}", out skillRoot))
  511. {
  512. Pack pack = (Pack) skillRoot;
  513. pack.OnBuySucceed();
  514. float newSpriteSize = 0.35f;
  515. Icon2.SetActive(false);
  516. Icon3.SetActive(false);
  517. Icon1.sprite = pack.Icon;
  518. Icon1.Resize(true, newSpriteSize, newSpriteSize);
  519. Icon1.transform.localPosition = new Vector2(0, 0);
  520. lab.GetComponent<Text>().text = pack.Name;
  521. InfoBoxManager.GardenInfoBox.Display($"{Language.GetStr(LanguageLabel.Common__Get)} {TransferLabel.PackSprite}{pack.Name}", 10, Color.white, ResourceManager.LoadSprite(ResourceLabel.Atlas, Folder.Atlas));
  522. }
  523. else
  524. {
  525. Debug.LogWarning($"Unknown id {mailReward.Value}");
  526. }
  527. }
  528. else if (mailReward.Key == "close")
  529. {
  530. List<int> idList = Auxiliary.StringToInts(' ', mailReward.Value, new List<int>());
  531. CloseItem closeItem;
  532. for (int i = 0; i < idList.Count; i++)
  533. {
  534. if (PlayerManager.CloseItemDictionary.TryGetValue(idList[i], out closeItem))
  535. {
  536. if (closeItem.IsBought == false)
  537. {
  538. closeItem.Unlock();
  539. PlayerManager.BoughtCloseIDs.UniqueAdd(idList[i]);
  540. }
  541. float newSize = 0.6f;
  542. float newSpriteSize = closeItem.PixelSize*newSize/closeItem.Sprites[0].rect.width;
  543. closeItem.SetupUI(newSpriteSize, new Vector2(), Icon1, Icon3, Icon2);
  544. lab.text = closeItem.Name;
  545. InfoBoxManager.GardenInfoBox.Display($"{Language.GetStr(LanguageLabel.Common__Get)} {TransferLabel.CloseSprite}{closeItem.Name}", 10, Color.white, ResourceManager.LoadSprite(ResourceLabel.Atlas, Folder.Atlas));
  546. }
  547. else
  548. {
  549. Debug.LogWarning($"Unknown id {idList[i]}");
  550. }
  551. }
  552. }
  553. else if (mailReward.Key == "flower")
  554. {
  555. List<int> idList = Auxiliary.StringToInts(' ', mailReward.Value, new List<int>());
  556. FlowerInfo flowerInfo;
  557. for (int i = 0; i < idList.Count; i++)
  558. {
  559. if (GardenManager.FlowerInfoDictionary.TryGetValue(idList[i], out flowerInfo))
  560. {
  561. flowerInfo.Add();
  562. float newSpriteSize = 0.225f;
  563. Icon2.SetActive(false);
  564. Icon3.SetActive(false);
  565. Icon1.sprite = flowerInfo.Icon;
  566. Icon1.Resize(true, newSpriteSize, newSpriteSize);
  567. Icon1.transform.localPosition = new Vector2(0, 0);
  568. lab.text = flowerInfo.Name;
  569. InfoBoxManager.GardenInfoBox.Display($"{Language.GetStr(LanguageLabel.Common__Get)} {TransferLabel.FlowerSprite}{flowerInfo.Name}", 10, Color.white, ResourceManager.LoadSprite(ResourceLabel.Atlas, Folder.Atlas));
  570. }
  571. else
  572. {
  573. Debug.LogWarning($"Unknown id {idList[i]}");
  574. }
  575. }
  576. }
  577. else if (mailReward.Key == "coin")
  578. {
  579. Manager.AddCoin(double.Parse(mailReward.Value), StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Mail);
  580. float newSpriteSize = 0.75f;
  581. Icon2.SetActive(false);
  582. Icon3.SetActive(false);
  583. Icon1.sprite = ResourceManager.LoadSprite(ResourceLabel.Gold, Folder.UI);
  584. Icon1.Resize(true, newSpriteSize, newSpriteSize);
  585. Icon1.transform.localPosition = new Vector2(0, 0);
  586. lab.text = Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value));
  587. InfoBoxManager.GardenInfoBox.Display($"{Language.GetStr(LanguageLabel.Common__Get)} {TransferLabel.CoinSprite}{Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value))}", 10, Color.white, ResourceManager.LoadSprite(ResourceLabel.Atlas, Folder.Atlas));
  588. }
  589. else if (mailReward.Key == "diamond")
  590. {
  591. Manager.AddDiamond(double.Parse(mailReward.Value), StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Mail);
  592. float newSpriteSize = 0.75f;
  593. Icon2.SetActive(false);
  594. Icon3.SetActive(false);
  595. Icon1.sprite = ResourceManager.LoadSprite(ResourceLabel.Diamond, Folder.UI);
  596. Icon1.Resize(true, newSpriteSize, newSpriteSize);
  597. Icon1.transform.localPosition = new Vector2(0, 0);
  598. lab.text = Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value));
  599. InfoBoxManager.GardenInfoBox.Display($"{Language.GetStr(LanguageLabel.Common__Get)} {TransferLabel.DiamondSprite}{Auxiliary.ShrinkNumberStr(double.Parse(mailReward.Value))}", 10, Color.white, ResourceManager.LoadSprite(ResourceLabel.Atlas, Folder.Atlas));
  600. }
  601. else
  602. {
  603. Debug.Log(mailReward.Key);
  604. }
  605. }
  606. public static void DecodeMailXmlStr(string mailXml)
  607. {
  608. MailRewardList = new List<MailReward>();
  609. XmlDocument xmlDoc = new XmlDocument();
  610. try
  611. {
  612. xmlDoc.LoadXml(mailXml);
  613. }
  614. catch (Exception)
  615. {
  616. return;
  617. }
  618. XmlNodeList rewardNodeList = xmlDoc.SelectSingleNode("mail").SelectNodes("OneTimeReward");
  619. List<string> receivedIdList = Auxiliary.StringToStrings(' ', ConfigManager.GetStringFormConfig(PlayerConfigLabel.OneTimeReward), new List<string>());
  620. for (int i = 0; i < rewardNodeList.Count; i++)
  621. {
  622. string id = rewardNodeList[i].SelectSingleNode("id").InnerText;
  623. if (receivedIdList.Contains(id))
  624. {
  625. continue;
  626. }
  627. DateTime startTime = DateTime.Parse(rewardNodeList[i].SelectSingleNode("start").InnerText);
  628. DateTime endTime = DateTime.Parse(rewardNodeList[i].SelectSingleNode("end").InnerText);
  629. if (CurrentDateTime < startTime || CurrentDateTime > endTime)
  630. {
  631. continue;
  632. }
  633. XmlNodeList targetIdNodeList = rewardNodeList[i].SelectSingleNode("targets").SelectNodes("id");
  634. for (int j = 0; j < targetIdNodeList.Count; j++)
  635. {
  636. if (targetIdNodeList[j].InnerText == ID)
  637. {
  638. XmlNodeList xmlNodeList = rewardNodeList[i].SelectSingleNode("reward").ChildNodes;
  639. for (int k = 0; k < xmlNodeList.Count; k++)
  640. {
  641. MailRewardList.Add(new MailReward(id, xmlNodeList[k].Name, xmlNodeList[k].InnerText));
  642. }
  643. break;
  644. }
  645. }
  646. }
  647. }
  648. public static void GetBuyPackLimitFlag()
  649. {
  650. GetUrlAddress
  651. (
  652. data =>
  653. {
  654. BuyPackLimitFlag = Auxiliary.StringToBool(data["l"][0]["val"].ToJson().Trim('"'), true);
  655. if (Application.platform == RuntimePlatform.Android)
  656. {
  657. BuyPackLimitFlag = true;
  658. }
  659. if (ConfigManager.configDocument != null)
  660. {
  661. ConfigManager.SaveBoolToConfig(PlayerConfigLabel.PackLock, BuyPackLimitFlag);
  662. }
  663. }
  664. );
  665. }
  666. public static void GetAlipayFlag()
  667. {
  668. GetUrlAddress
  669. (
  670. data =>
  671. {
  672. IAPManager.UseAlipayOnIOS = Auxiliary.StringToBool(data["l"][2]["val"].ToJson().Trim('"'), false);
  673. }
  674. );
  675. }
  676. public static void GetProductID(string id, URLRequest.URLRequestCallBackDelegate callback)
  677. {
  678. URLRequestData urlData = new URLRequestData();
  679. urlData.Add("t", 1);
  680. urlData.Add("i", id);
  681. urlData.Add("u", LoginCallbackData.Inst_Object["i"].ToJson().Trim('"'));
  682. URLRequest.CreateStrURLRequest(true, GetProductIDURL, urlData, callback, URLRequest.Method.POST);
  683. }
  684. public static void Login(URLRequest.URLRequestJsonCallBackDelegate callback = null)
  685. {
  686. URLRequestData urlData = new URLRequestData();
  687. urlData.Add("u", SystemInfo.deviceUniqueIdentifier);
  688. URLRequest.CreateURLRequest(false, LoginURL, urlData, LoginCallback + callback, URLRequest.Method.POST);
  689. }
  690. private static void LoginCallback(JsonData jsonData)
  691. {
  692. Inited = true;
  693. if (jsonData.Inst_Object.ContainsKey("c"))
  694. {
  695. IsConnect = true;
  696. LoginCallbackData = jsonData;
  697. CurrentDateTime = DateUtil.GetTime(jsonData["time"].ToJson());
  698. PraiseAmt = int.Parse(jsonData["p"].ToJson().Trim('"'));
  699. if (ConfigManager.PlayerDocumentDamageFlag)
  700. {
  701. ID = jsonData["o"].ToString();
  702. SerialNumber = jsonData["i"].ToString();
  703. }
  704. else if (ConfigManager.configDocument != null)
  705. {
  706. if (ConfigManager.GetStringFormConfig(PlayerConfigLabel.ID) == PlayerConfigLabel.DefaultID)
  707. {
  708. ID = jsonData["o"].ToString();
  709. if (Initializer.Inited)
  710. {
  711. ResourceManager.SetText(ObjectLabel.L_UserLab, ID);
  712. }
  713. }
  714. if (ConfigManager.GetStringFormConfig(PlayerConfigLabel.SerialNumber) == PlayerConfigLabel.DefaultID)
  715. {
  716. SerialNumber = LoginCallbackData["i"].ToString();
  717. }
  718. }
  719. if (FirstTimeConnectFlag)
  720. {
  721. FirstTimeConnectFlag = false;
  722. StaticsManager.GetInstance().ActOrReg(ID, DataEyeGA.AccountType.Official);
  723. }
  724. }
  725. else
  726. {
  727. IsConnect = false;
  728. }
  729. }
  730. public static void UploadConfig()
  731. {
  732. Manager.UploadConfigTimer = 0;
  733. URLRequestData urlData = new URLRequestData();
  734. urlData.Add("u", SerialNumber);
  735. urlData.Add("v", ReplayVersion);
  736. ConfigManager.SaveConfigDocument();
  737. urlData.Add("l", ConfigManager.ConfigDocument.OuterXml);
  738. URLRequest.CreateURLRequest(false, SaveURL, urlData, data => {}, URLRequest.Method.POST);
  739. }
  740. public static void GetTargetConfig(string id, URLRequest.URLRequestJsonCallBackDelegate callback)
  741. {
  742. URLRequestData urlData = new URLRequestData();
  743. urlData.Add("u", id);
  744. URLRequest.CreateURLRequest(true, OtherURL, urlData, callback, URLRequest.Method.POST);
  745. }
  746. public static void GetConfigByID(string id, URLRequest.URLRequestJsonCallBackDelegate callback)
  747. {
  748. URLRequestData urlData = new URLRequestData();
  749. urlData.Add("u", id);
  750. URLRequest.CreateURLRequest(true, DownloadURL, urlData, callback, URLRequest.Method.POST);
  751. }
  752. public static void GetConfigBySerialNumber(string serialNumber, URLRequest.URLRequestJsonCallBackDelegate callback)
  753. {
  754. URLRequestData urlData = new URLRequestData();
  755. urlData.Add("u", serialNumber);
  756. URLRequest.CreateURLRequest(true, DownloadURL, urlData, callback, URLRequest.Method.POST);
  757. }
  758. public static void GetRandomConfig(URLRequest.URLRequestJsonCallBackDelegate callback)
  759. {
  760. URLRequestData urlData = new URLRequestData();
  761. urlData.Add("i", "");
  762. URLRequest.CreateURLRequest(false, RandomURL, urlData, callback, URLRequest.Method.POST);
  763. }
  764. public static void GetThanksGiftInfo(Action<JsonData> callback, Action failed)
  765. {
  766. URLRequestData urlData = new URLRequestData();
  767. URLRequest.CreateURLRequest
  768. (
  769. false,
  770. ThanksGiftInfoURL,
  771. urlData,
  772. jData =>
  773. {
  774. if (jData.Inst_Object.ContainsKey("l"))
  775. {
  776. callback.Invoke(jData["l"]);
  777. }
  778. else
  779. {
  780. failed.Invoke();
  781. }
  782. }
  783. );
  784. }
  785. private static string SmtpHost = "smtp.163.com";
  786. private static string ReporterMailAccount = "dashgamegarden@163.com";
  787. private static string ReporterMailPassword = "cs670cs";
  788. public static void ReportIssue()
  789. {
  790. ResourceManager.Get(ObjectLabel.Lb_Info).TweenBacCG();
  791. string emailAddress = ResourceManager.Get<Text>(ObjectLabel.Lb_InputLab0).text;
  792. if (string.IsNullOrEmpty(emailAddress) || !emailAddress.Contains("@"))
  793. {
  794. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Lb_Send3));
  795. return;
  796. }
  797. string content = ResourceManager.Get<Text>(ObjectLabel.Lb_InputLab).text;
  798. if (string.IsNullOrEmpty(content))
  799. {
  800. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Lb_Send2));
  801. }
  802. else if(ReportIssueContent == content)
  803. {
  804. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Lb_Send1));
  805. }
  806. else
  807. {
  808. MailMessage mailMessage = new MailMessage();
  809. mailMessage.To.Add(new MailAddress(ReportMailAddress));
  810. mailMessage.From = new MailAddress(ReporterMailAccount);
  811. ReportIssueContent = content;
  812. mailMessage.Body = emailAddress + '\n' + ReportIssueContent + '\n' + GetSystemInfo();
  813. mailMessage.Subject = ID + " MyLovelyGargen Issue";
  814. SmtpClient smtpClient = new SmtpClient(SmtpHost);
  815. smtpClient.Credentials = new MyCredentials(ReporterMailAccount, ReporterMailPassword);
  816. smtpClient.SendAsync(mailMessage, "Async");
  817. Bubble.Show(null, Language.GetStr(LanguageLabel.UI__Lb_Send0));
  818. }
  819. }
  820. public static string GetSystemInfo()
  821. {
  822. StringBuilder sb = new StringBuilder();
  823. sb.AppendLine("deviceType :" + SystemInfo.deviceType.ToString());
  824. sb.AppendLine("deviceName :" + SystemInfo.deviceName.ToString());
  825. sb.AppendLine("deviceModel :" + SystemInfo.deviceModel.ToString());
  826. sb.AppendLine("deviceUniqueIdentifier :" + SystemInfo.deviceUniqueIdentifier.ToString());
  827. sb.AppendLine("graphicsDeviceID :" + SystemInfo.graphicsDeviceID.ToString());
  828. sb.AppendLine("graphicsDeviceType :" + SystemInfo.graphicsDeviceType.ToString());
  829. sb.AppendLine("graphicsDeviceName :" + SystemInfo.graphicsDeviceName.ToString());
  830. sb.AppendLine("graphicsShaderLevel :" + SystemInfo.graphicsShaderLevel.ToString());
  831. sb.AppendLine("graphicsMemorySize :" + SystemInfo.graphicsMemorySize.ToString());
  832. sb.AppendLine("graphicsDeviceVersion :" + SystemInfo.graphicsDeviceVersion.ToString());
  833. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  834. sb.AppendLine("graphicsDeviceVendor :" + SystemInfo.graphicsDeviceVendor.ToString());
  835. sb.AppendLine("graphicsDeviceVendorID :" + SystemInfo.graphicsDeviceVendorID.ToString());
  836. sb.AppendLine("npotSupport :" + SystemInfo.npotSupport.ToString());
  837. sb.AppendLine("maxTextureSize :" + SystemInfo.maxTextureSize.ToString());
  838. sb.AppendLine("operatingSystem :" + SystemInfo.operatingSystem.ToString());
  839. sb.AppendLine("operatingSystemFamily :" + SystemInfo.operatingSystemFamily.ToString());
  840. sb.AppendLine("processorType :" + SystemInfo.processorType.ToString());
  841. sb.AppendLine("processorCount :" + SystemInfo.processorCount.ToString());
  842. sb.AppendLine("processorFrequency :" + SystemInfo.processorFrequency.ToString());
  843. sb.AppendLine("copyTextureSupport :" + SystemInfo.copyTextureSupport.ToString());
  844. sb.AppendLine("graphicsMultiThreaded :" + SystemInfo.graphicsMultiThreaded.ToString());
  845. sb.AppendLine("supportedRenderTargetCount :" + SystemInfo.supportedRenderTargetCount.ToString());
  846. sb.AppendLine("supports3DTextures :" + SystemInfo.supports3DTextures.ToString());
  847. sb.AppendLine("supports2DArrayTextures :" + SystemInfo.supports2DArrayTextures.ToString());
  848. sb.AppendLine("supportsAccelerometer :" + SystemInfo.supportsAccelerometer.ToString());
  849. sb.AppendLine("supportsAudio :" + SystemInfo.supportsAudio.ToString());
  850. sb.AppendLine("supportsComputeShaders :" + SystemInfo.supportsComputeShaders.ToString());
  851. sb.AppendLine("supportsCubemapArrayTextures :" + SystemInfo.supportsCubemapArrayTextures.ToString());
  852. sb.AppendLine("supportsGyroscope :" + SystemInfo.supportsGyroscope.ToString());
  853. sb.AppendLine("supportsImageEffects :" + SystemInfo.supportsImageEffects.ToString());
  854. sb.AppendLine("supportsInstancing :" + SystemInfo.supportsInstancing.ToString());
  855. sb.AppendLine("supportsLocationService :" + SystemInfo.supportsLocationService.ToString());
  856. sb.AppendLine("supportsMotionVectors :" + SystemInfo.supportsMotionVectors.ToString());
  857. sb.AppendLine("supportsRawShadowDepthSampling :" + SystemInfo.supportsRawShadowDepthSampling.ToString());
  858. sb.AppendLine("supportsRenderToCubemap :" + SystemInfo.supportsRenderToCubemap.ToString());
  859. sb.AppendLine("supportsShadows :" + SystemInfo.supportsShadows.ToString());
  860. sb.AppendLine("supportsSparseTextures :" + SystemInfo.supportsSparseTextures.ToString());
  861. sb.AppendLine("supportsVibration :" + SystemInfo.supportsVibration.ToString());
  862. sb.AppendLine("systemMemorySize :" + SystemInfo.systemMemorySize.ToString());
  863. sb.AppendLine("usesReversedZBuffer :" + SystemInfo.usesReversedZBuffer.ToString());
  864. return sb.ToString();
  865. }
  866. }