| 1234567891011121314151617181920212223242526272829303132 |
- using System;
- using System.Collections;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- /* Http控制器-验证码 */
- public class CaptchaController : JCUnityLib.Singleton<CaptchaController>
- {
- int[] builtInCaptchaList = {3825, 4472, 9483};
- public IEnumerator GetCaptcha(Image targetRenderImage, Action<int> cb)
- {
- if (targetRenderImage.sprite == null)
- {
- int codeA = builtInCaptchaList[UnityEngine.Random.Range(0, 3)];
- targetRenderImage.sprite = Resources.Load<Sprite>("Captcha/" + codeA);
- if (cb != null) cb(codeA);
- }
- int code = UnityEngine.Random.Range(1000, 10000);
- using (UnityWebRequest uwr = new UnityWebRequest(CommonConfig.gateServerURL + "/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));
- targetRenderImage.sprite = sprite;
- if (cb != null) cb(code);
- }
- }
- }
|