/// <summary> /// 创建临时二维码 /// </summary> /// <param name="wxappid"></param> /// <param name="expire_seconds">有效时间</param> /// <param name="scene_id">二维码参数</param> /// <returns></returns> public CreateQRCodeResult CreateTmpQRCode(string wxappid, int expire_seconds, int scene_id) { CreateQRCodeResult wxresult = null; int retrycount = 0; int maxretrycount = 3; string access_token = ""; access_token = GetAccessToken(wxappid); string url = string.Format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}", access_token); string sendcontent = "{\"expire_seconds\": " + expire_seconds.ToString() + ", \"action_name\": \"QR_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + scene_id.ToString() + "}}}"; while (retrycount < maxretrycount) { wxresult = ObjectSeriallizeHelper.JsonToObject <CreateQRCodeResult>(WXInterfaceHttpRequest(url, sendcontent, "post")); if (wxresult.errcode == 0) { break; } else { if (wxresult.errcode == 40014 || wxresult.errcode == 42001) { access_token = GetAccessToken(wxappid, true); } retrycount++; } } return(wxresult); }
/// <summary> /// 创建临时二维码 /// </summary> private void CreateTmpQRCode() { string errmsg = ""; string wxappid = WXApiInfo.wxappid; int scene_id = 0; BLLSequence myseq = new BLLSequence(); bool result = myseq.GetCreateTmpQRCodeScene_id(ref scene_id, ref errmsg); if (result) { CreateQRCodeResult info = new CreateQRCodeResult(); CallWXInterface mybll = new CallWXInterface(); DateTime failuredate = DateTime.Now.AddSeconds(3600); info = mybll.CreateTmpQRCode(wxappid, 3600, scene_id); BLLQRManage myqr = new BLLQRManage(); result = myqr.CreateTmpQRCode(info.ticket, info.expire_seconds, info.url, 0, scene_id, "绑定用户", failuredate, ref errmsg); if (result) { string str = "\"url\":\"" + info.url + "\""; Response.Write(outjson.Replace("#code#", "0").Replace("#msg#", "").Replace("\"data\":null", str)); Response.End(); } else { Response.Write(outjson.Replace("#code#", "-1").Replace("#msg#", errmsg)); Response.End(); } } else { Response.Write(outjson.Replace("#code#", "-1").Replace("#msg#", errmsg)); Response.End(); } }