| 123456789101112131415161718192021222324252627282930313233343536373839 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- //验证码控制器
- public class CaptchaController : Singleton<CaptchaController>
- {
- public IEnumerator GetCaptcha(CaptchaType type, Image targetRenderImage)
- {
- int code = UnityEngine.Random.Range(1000, 10000);
- UnityWebRequest uwr = new UnityWebRequest(CommonConfig.businessServerURI + "/api/createCaptcha?code=" + code, UnityWebRequest.kHttpVerbGET);
- uwr.downloadHandler = new DownloadHandlerTexture();
- yield return uwr.SendWebRequest();
- Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
- Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
- switch (type) {
- case CaptchaType.Login:
- captcha_Login = code;
- targetRenderImage.sprite = sprite;
- break;
- case CaptchaType.LoginPhone:
- captcha_LoginPhone = code;
- targetRenderImage.sprite = sprite;
- break;
- case CaptchaType.Register:
- captcha_Register = code;
- targetRenderImage.sprite = sprite;
- break;
- }
- }
- public enum CaptchaType {
- Login, LoginPhone, Register
- }
- public int captcha_Login = -222222222;
- public int captcha_LoginPhone = -222222222;
- public int captcha_Register = -222222222;
- }
|