public async Task<string> GetDescription()
{
// 调用前 需要去微信小程序后台开启消息推送功能和申请模板
//var daz = DbContext.Instance.Queryable<ProduceOrderEntity>().ToList();
//var data = db.Queryable<ProduceOrderEntity>().ToList();
//var list = db.Queryable<ProduceOrderEntity>().ToList();
//appid secret可去微信小程序管理后台查看
var url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxb43d289053371820&secret=c38750e7b81d385cab9727f707a3de34";
var resp = await new HttpClient().GetStringAsync(url);
var json = Newtonsoft.Json.JsonConvert.DeserializeObject<jsonmodel>(resp);
string _url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + json.access_token;
WxSetModel wm = new WxSetModel();
string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(wm);
// 调用小程序API
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
request.Method = "POST";
request.Timeout = 5000;
request.ContentType = "application/json;charset=UTF-8";
byte[] byteData = Encoding.UTF8.GetBytes(jsonParam);
int length = byteData.Length;
request.ContentLength = length;
using (Stream writer = request.GetRequestStream())
{
writer.Write(byteData, 0, length);
writer.Close();
}
string jsonStrings = string.Empty;
using (HttpWebResponse responses = (HttpWebResponse)request.GetResponse())
{
using (Stream streams = responses.GetResponseStream())
{
using (StreamReader readers = new StreamReader(streams, Encoding.UTF8))
{
jsonStrings = readers.ReadToEnd();
responses.Close();
streams.Close();
readers.Close();
}
}
}
//这里是返回的数据
JObject jo = (JObject)JsonConvert.DeserializeObject(jsonStrings);
string errcode = jo["errcode"].ToString();
string errmsg = jo["errmsg"].ToString();
return "让 .NET 开发更简单,更通用,更流行。";
}
调用微信通知服务代码块
最新推荐文章于 2023-12-05 09:52:51 发布