CaptchaController.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using UnityEngine.UI;
  6. //验证码控制器
  7. public class CaptchaController : Singleton<CaptchaController>
  8. {
  9. public IEnumerator GetCaptcha(CaptchaType type, Image targetRenderImage)
  10. {
  11. int code = UnityEngine.Random.Range(1000, 10000);
  12. UnityWebRequest uwr = new UnityWebRequest(CommonConfig.businessServerURI + "/api/createCaptcha?code=" + code, UnityWebRequest.kHttpVerbGET);
  13. uwr.downloadHandler = new DownloadHandlerTexture();
  14. yield return uwr.SendWebRequest();
  15. Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
  16. Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
  17. switch (type) {
  18. case CaptchaType.Login:
  19. captcha_Login = code;
  20. targetRenderImage.sprite = sprite;
  21. break;
  22. case CaptchaType.LoginPhone:
  23. captcha_LoginPhone = code;
  24. targetRenderImage.sprite = sprite;
  25. break;
  26. case CaptchaType.Register:
  27. captcha_Register = code;
  28. targetRenderImage.sprite = sprite;
  29. break;
  30. }
  31. }
  32. public enum CaptchaType {
  33. Login, LoginPhone, Register
  34. }
  35. public int captcha_Login = -222222222;
  36. public int captcha_LoginPhone = -222222222;
  37. public int captcha_Register = -222222222;
  38. }