/// <summary> /// 生成现金券 | 域名/wxbackstage/client/coupon/generate | POST /// worth | Integer | 现金券金额,单位:分 | true /// boxId | String | 该现金券绑定的盒子ID | true /// userId | Integer | 用户ID | true /// </summary> public void HttpSendPostHddPlayerCouponInfo(int userId, int account, string boxId) { //account单位是人民币元. //worth单位是人民币分. int worth = account * 100; //单位从元转换为分. Debug.Log("Unity:" + "HttpSendPostHddSubPlayerMoney..."); Debug.Log("Unity: memberId == " + userId + ", worth == " + worth + "分, boxId == " + boxId); //生成现金券的url. string url = m_BoxLoginData.m_Address + "/wxbackstage/client/coupon/generate"; Debug.Log("Unity: url == " + url); Encoding encoding = Encoding.GetEncoding("utf-8"); PostDataPlayerCouponInfo postDt = new PostDataPlayerCouponInfo(worth, boxId, userId); //"{\"worth\":100,\"boxId\":\"123456\",\"userId\":93124}" //发送的消息. string jsonData = JsonMapper.ToJson(postDt); byte[] postData = Encoding.UTF8.GetBytes(jsonData); PostHttpResponse postHttpResponse = new PostHttpResponse(); HttpWebResponse response = postHttpResponse.CreatePostHttpResponse(url, postData, encoding); //打印返回值. Stream stream = null; //获取响应的流. try { //以字符流的方式读取HTTP响应. stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream); //创建一个stream读取流 string msg = sr.ReadToEnd(); //从头读到尾,放到字符串html Debug.Log("unity: msg == " + msg); //{"code":0,"message":"成功","data":{"id":4,"couponId":"36ecce4e-0b5c-4808-8284-18c1fad8bc27", //"worth":100,"boxId":"408d5cbc1371leitingzhanche","createTime":"2018-10-27T03:41:43.025+0000", //"userId":93124}} JsonData jd = JsonMapper.ToObject(msg); if (Convert.ToInt32(jd["code"].ToString()) == (int)BoxLoginRt.Success) { //红点点支付平台玩家代金券添加成功. } else { //红点点支付平台玩家代金券添加失败. Debug.Log("Unity:" + "HttpSendPostHddSubPlayerMoney failed! code == " + jd["code"]); } } finally { //释放资源. if (stream != null) { stream.Close(); } if (response != null) { response.Close(); } } }
/// <summary> /// 消费用户余额 | 域名/wxbackstage/memberAccount/spend | POST /// memberId | Integer | 用户ID,等同于 UserID /// account | Integer | 消费金额,单位分,1块钱=100分 /// </summary> public void HttpSendPostHddSubPlayerMoney(int userId, int account) { Debug.Log("Unity:" + "HttpSendPostHddSubPlayerMoney..."); Debug.Log("Unity: memberId == " + userId + ", account == " + account); //消费用户余额的url. string url = m_BoxLoginData.m_Address + "/wxbackstage/memberAccount/spend"; Debug.Log("Unity: url == " + url); Encoding encoding = Encoding.GetEncoding("utf-8"); PostDataHddSubPlayerMoney postDt = new PostDataHddSubPlayerMoney(userId, account); //"{\"memberId\":93124,\"account\":100}" //发送的消息. string jsonData = JsonMapper.ToJson(postDt); byte[] postData = Encoding.UTF8.GetBytes(jsonData); PostHttpResponse postHttpResponse = new PostHttpResponse(); HttpWebResponse response = postHttpResponse.CreatePostHttpResponse(url, postData, encoding); //打印返回值. Stream stream = null; //获取响应的流. try { //以字符流的方式读取HTTP响应. stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream); //创建一个stream读取流 string msg = sr.ReadToEnd(); //从头读到尾,放到字符串html //{"code":-1,"message":"该用户没有充值信息,不能扣款!"} //{"code":0,"message":"成功","data":{"id":4,"openId":"oefFM5cqhWSws1BVxgzuLTLWKAnk","account":1,"memberId":93124}} Debug.Log("unity: msg == " + msg); JsonData jd = JsonMapper.ToObject(msg); if (Convert.ToInt32(jd["code"].ToString()) == (int)BoxLoginRt.Success) { //红点点支付平台扣费成功. } else { //红点点支付平台扣费失败. Debug.Log("Unity:" + "HttpSendPostHddSubPlayerMoney failed! code == " + jd["code"]); } } finally { //释放资源. if (stream != null) { stream.Close(); } if (response != null) { response.Close(); } } }
/// <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(); } }