微信生成二维码开发

微信二维码开发说明文档:https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html

1.获取access_token


	//获取access_token
	string access_tokenURL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + key + "";

	JavaScriptSerializer Serializers = new JavaScriptSerializer();

	AccessToken listAccessToken = Serializers.Deserialize<AccessToken>(HttpPost(access_tokenURL));

	string access_token = listAccessToken.access_token;

2.获取ticket


	//临时二维码
	string poster = "{\"action_name\": \"QR_STR_SCENE\",\"action_info\": {\"scene\": { \"scene_id\": " + 12 + " } }";//二维码请求格式
	string ticket = GetPage("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + access_token + "", poster + "");//获取aticket 
	

3.获取二维码ticket后,用ticket换取二维码图片


	var model = Newtonsoft.Json.JsonConvert.DeserializeObject<Hashtable>(ticket);//json字符串转数组
	string ewmUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + model["ticket"];

你可能感兴趣的:(小程序开发)