调用微信接口前需要准备的内容。
1.微信公众平台的appid
2.微信公众平台的secret
3..获取tokenid
4.获取ticket
5.生成签名的随机串
6.生成签名的时间戳
7.生成签名
================================================================================
1.微信公众平台的appid
2.微信公众平台的secret
这两者需要登录到申请的微信公众平台中去获取,建议写在配置文件中
================================================================================
3.获取tokenid
public static string GetWxTokenId()
{
string token = "";
string url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appid, secret);
//向上面的地址发起httpget请求
//这里是封装的一个http请求的类
string content = HttpHelper.HttpGet(url);
if (!string.IsNullOrEmpty(content))
{
var obj = JsonConvert.DeserializeObject<TokenResult>(content);
if (!obj.errcode.HasValue)
{
token = obj.access_token;
}
}
return token;
}