CaptchaController.cs 947 B

1234567891011121314151617181920212223
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Networking;
  6. using UnityEngine.UI;
  7. /* Http控制器-验证码 */
  8. public class CaptchaController : Singleton<CaptchaController>
  9. {
  10. public IEnumerator GetCaptcha(Image targetRenderImage, Action<int> cb)
  11. {
  12. int code = UnityEngine.Random.Range(1000, 10000);
  13. using (UnityWebRequest uwr = new UnityWebRequest(CommonConfig.businessServerURI + "/api/createCaptcha?code=" + code, UnityWebRequest.kHttpVerbGET)) {
  14. uwr.downloadHandler = new DownloadHandlerTexture();
  15. yield return uwr.SendWebRequest();
  16. Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
  17. Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
  18. targetRenderImage.sprite = sprite;
  19. if (cb != null) cb(code);
  20. }
  21. }
  22. }