// Use this for initialization void Start() { m_LastTimeVal = Time.time; if (ErWeiMaUI.GetInstance() != null) { ErWeiMaUI.GetInstance().SetActive(false); } }
/// <summary> /// 向微信请求游戏虚拟手柄小程序的二维码图片信息. /// </summary> void HttpRequestWeiXinXiaoChengXuErWeiMa(WeiXinXiaoChengXuData data) { string url = data.qrcodeUrl; Encoding encoding = Encoding.GetEncoding("utf-8"); postData postdata = new postData(); postdata.scene = data.scene; postdata.page = data.page; Debug.Log("HttpRequestWeiXinXiaoChengXuErWeiMa -> url ==== " + url); Debug.Log("HttpRequestWeiXinXiaoChengXuErWeiMa -> scene ==== " + postdata.scene); Debug.Log("HttpRequestWeiXinXiaoChengXuErWeiMa -> page ==== " + postdata.page); string str = JsonMapper.ToJson(postdata); byte[] postData = Encoding.UTF8.GetBytes(str); PostHttpResponse postHttpResponse = new PostHttpResponse(); HttpWebResponse response = postHttpResponse.CreatePostHttpResponse(url, postData, encoding); //打印返回值. Stream stream = null; //获取响应的流. try { //以字符流的方式读取HTTP响应. stream = response.GetResponseStream(); //System.Drawing.Image.FromStream(stream).Save(path); MemoryStream ms = null; byte[] buffer = new byte[response.ContentLength]; int offset = 0, actuallyRead = 0; do { actuallyRead = stream.Read(buffer, offset, buffer.Length - offset); offset += actuallyRead; }while (actuallyRead > 0); ms = new MemoryStream(buffer); byte[] buffurPic = ms.ToArray(); Debug.Log("Unity: buffurPic.length ==================== " + buffurPic.Length); string path = m_BoxLoginData.WX_XiaoChengXu_ErWeiMa_Path; Debug.Log("Unity: path ==== " + path); File.WriteAllBytes(path, buffurPic); } finally { //释放资源. if (stream != null) { stream.Close(); } if (response != null) { response.Close(); } } //更新微信小程序二维码. if (ErWeiMaUI.GetInstance() != null) { ErWeiMaUI.GetInstance().ReloadGameWXPadXiaoChengXuErWeiMa(); } }