public JsonResponse SetIndustry() { string accesstoken = GetAccesstoken(); string url = @"https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=" + accesstoken; HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.Method = "POST"; httpItem.Postdata = JsonConvert.SerializeObject(new { industry_id1 = "1", industry_id2 = "4", industry_id3 = "10", industry_id4 = "11", industry_id5 = "12" }); HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); var reshtml = httpResult.Html; LogHelper.WriteLog("SetIndustry:" + reshtml); return(FastResponse(reshtml)); }
private BaseModel BuildPost(object data, string url) { BaseModel model = null; try { //string accesstoken = GetAccesstoken(); //string url = @"https://api.weixin.qq.com/customservice/kfaccount/add?access_token=" + accesstoken; HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.Method = "POST"; httpItem.Postdata = JsonConvert.SerializeObject(data); HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); string reshtml = httpResult.Html; LogHelper.WriteLog("reshtml:" + reshtml); model = JsonConvert.DeserializeObject <BaseModel>(reshtml); } catch (Exception ex) { LogHelper.WriteLog(ex, "BuildPost"); } return(model); }
/// <summary> /// openid换取基本信息 /// </summary> /// <param name="openid"></param> /// <returns></returns> private WxUserBaseInfoModel GetBaseByOpenid(string openid, string acctoken) { WxUserBaseInfoModel res = new WxUserBaseInfoModel(); if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(acctoken)) { return(res); } try { string url2 = @"https://api.weixin.qq.com/sns/userinfo?access_token=" + acctoken + "&openid=" + openid + "&lang=zh_CN"; HttpItem httpItem2 = new HttpItem(); httpItem2.URL = url2; httpItem2.Method = "GET"; HttpHelper helper2 = new HttpHelper(); HttpResult httpResult2 = helper2.GetHtml(httpItem2); res = JsonConvert.DeserializeObject <WxUserBaseInfoModel>(httpResult2.Html); LogHelper.WriteLog("html2userinfo:" + httpResult2.Html); } catch (Exception ex) { LogHelper.WriteLog(ex, "GetBaseByOpenid"); } return(res); }
public JsonResponse AddCustomerService() { string accesstoken = GetAccesstoken(); string url = @"https://api.weixin.qq.com/customservice/kfaccount/add?access_token=" + accesstoken; HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.Method = "POST"; httpItem.Postdata = JsonConvert.SerializeObject(new { kf_account = "rodman", nickname = "Rodman客服", password = "******" }); HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); var reshtml = httpResult.Html; LogHelper.WriteLog("reshtml:" + reshtml); var model = JsonConvert.DeserializeObject <AccesstokenModel>(reshtml); if (model.errcode == 0) { return(FastResponse("JUST OK")); } else { return(FastResponse(reshtml)); } }
/// <summary> /// code换取openid和网页授权acctoken /// </summary> /// <returns></returns> private WxOauthModel GetOpenidByCode() { WxOauthModel res = new WxOauthModel(); try { //第一步code换取accesstoken、openid string code = HttpContext.Current.Request.QueryString["code"]?.ToString(); LogHelper.WriteLog("code:" + code); //获取网页授权accesstoken string url = $"https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + WchartApiConst.appid + "&secret=" + WchartApiConst.appsecret + "&code=" + code + "&grant_type=authorization_code"; HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.Method = "GET"; HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); var reshtml = httpResult.Html; LogHelper.WriteLog("html1:" + reshtml); res = JsonConvert.DeserializeObject <WxOauthModel>(reshtml); } catch (Exception ex) { LogHelper.WriteLog(ex, "GetOpenid"); } return(res); }
/// <summary> /// 获取接口调用accesstoken,这里指普通的那个 /// </summary> /// <returns></returns> private string GetAccesstoken() { string accesstoken = ""; try { accesstoken = HttpContext.Current.Cache.Get(WchartApiConst.accesstokenkey)?.ToString() ?? ""; if (!string.IsNullOrEmpty(accesstoken)) { return(accesstoken); } string url = $"{WchartApiConst.access_token}?grant_type=client_credential&appid={WchartApiConst.appid}&secret={WchartApiConst.appsecret}"; HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.Method = "GET"; HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); var reshtml = httpResult.Html; LogHelper.WriteLog("reshtml:" + reshtml); var model = JsonConvert.DeserializeObject <AccesstokenModel>(reshtml); if (model.errcode == 0) { HttpContext.Current.Cache.Insert(WchartApiConst.accesstokenkey, model.access_token, null, DateTime.Now.AddMinutes(120), System.Web.Caching.Cache.NoSlidingExpiration); return(model.access_token); } } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { } return(string.Empty); }
public JsonResponse CreateMenu() { string accesstoken = GetAccesstoken(); string url = @"https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accesstoken; var buttonlist = new List <MenuModel>(); buttonlist.Add(new MenuModel { name = "今朝有酒t7", sub_button = new List <MenuModel>() { new MenuModel { type = "view", name = "获取info", url = @"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WchartApiConst.appid + "&redirect_uri=http%3a%2f%2frodman.nat300.top%2fapi%2fwchart%2fGetUserBaseInfo&response_type=code&scope=snsapi_userinfo&state=aaa&connect_redirect=1#wechat_redirect" } } }); buttonlist.Add(new MenuModel { name = "今朝有酒tt7", sub_button = new List <MenuModel>() { new MenuModel { type = "view", name = "获取info2", url = @"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WchartApiConst.appid + "&redirect_uri=http%3a%2f%2frodman.nat300.top%2fwsdk%2findex&response_type=code&scope=snsapi_userinfo&state=aaa&connect_redirect=1#wechat_redirect" } } }); HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.PostEncoding = System.Text.Encoding.UTF8; httpItem.Encoding = System.Text.Encoding.UTF8; httpItem.Method = "POST"; httpItem.Postdata = JsonConvert.SerializeObject(new { button = buttonlist }); HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); var reshtml = httpResult.Html; LogHelper.WriteLog("reshtml:" + reshtml); var model = JsonConvert.DeserializeObject <AccesstokenModel>(reshtml); if (model.errcode == 0) { return(FastResponse("just ok")); } else { return(FastResponse(reshtml)); } }
public JsonResponse GetPrivateTemplate() { string accesstoken = GetAccesstoken(); string url = @"https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=" + accesstoken; HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.Method = "GET"; HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); var reshtml = httpResult.Html; LogHelper.WriteLog("GetPrivateTemplate:" + reshtml); return(FastResponse(reshtml)); }
public JsonResponse GetMenu() { string accesstoken = GetAccesstoken(); string url = @"https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + accesstoken; HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.Method = "GET"; HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); var reshtml = httpResult.Html; LogHelper.WriteLog("getmenu html:" + reshtml); var model = JsonConvert.DeserializeObject <AccesstokenModel>(reshtml); return(FastResponse(reshtml)); }
private string BuildGet(string url) { var reshtml = ""; try { string accesstoken = GetAccesstoken(); //string url = @"https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + accesstoken; HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.Method = "GET"; HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); reshtml = httpResult.Html; LogHelper.WriteLog("getmenu html:" + reshtml); //var model = JsonConvert.DeserializeObject<AccesstokenModel>(reshtml); } catch (Exception ex) { LogHelper.WriteLog(ex, "BuildGet"); } return(reshtml); }
public JsonResponse DeleteMenu() { string accesstoken = GetAccesstoken(); string url = $"https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + accesstoken; HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.Method = "GET"; HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); var reshtml = httpResult.Html; LogHelper.WriteLog("delete html:" + reshtml); var model = JsonConvert.DeserializeObject <AccesstokenModel>(reshtml); if (model.errcode == 0) { return(FastResponse("OK")); } else { return(FastResponse(reshtml)); } }
public JsonResponse SendTemplate() { string accesstoken = GetAccesstoken(); string url = @"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accesstoken; HttpItem httpItem = new HttpItem(); httpItem.URL = url; httpItem.Method = "POST"; httpItem.Postdata = JsonConvert.SerializeObject(new { touser = "******", template_id = "pr3N9o1zbPh9V5uFkiPIeI4m0u2uG8sqS-YaaNlBlE0", url = "", miniprogram = new { appid = "", pagepath = "" }, data = new { first = new { value = "恭喜你购买成功!", color = "#173177" }, keyword1 = new { value = "Rodman", color = "#173177" }, keyword2 = new { value = "18888888888", color = "#173177" }, keyword3 = new { value = "102030405060708090", color = "#173177" }, keyword4 = new { value = "已发货", color = "#173177" }, keyword5 = new { value = "1000.0¥", color = "#173177" }, remark = new { value = "欢迎再次", color = "#173177" }, } }); HttpHelper helper = new HttpHelper(); HttpResult httpResult = helper.GetHtml(httpItem); var reshtml = httpResult.Html; LogHelper.WriteLog("SendTemplate:" + reshtml); var model = JsonConvert.DeserializeObject <BaseReturnModel>(reshtml); if (model.errcode == 0) { return(FastResponse("JUST OK")); } else { return(FastResponse(reshtml)); } }