/// <summary>
/// 小程序码 小程序接收需要用
decodeURIComponent(options.scene)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=****&secret=****";
//请求url以获取数据
string result = HttpService.Get(url);
//保存access_token,用于收货地址获取
LitJson.JsonData jd = LitJson.JsonMapper.ToObject(result);
string access_token = (string)jd["access_token"];
string _url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + access_token;
string strURL = _url;
System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
request.Method = "POST";
request.ContentType = "application/json;charset=UTF-8";
JsonData _data = new JsonData();
_data["page"] = "pages/ErWeiMa/ErWeiMa";
_data["scene"] = "1";
_data["width"] = "430";
string _jso = _data.ToJson();
//string paraUrlCoded = param;
byte[] payload;
//payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
payload = System.Text.Encoding.UTF8.GetBytes(_jso);
request.ContentLength = payload.Length;
Stream writer = request.GetRequestStream();
writer.Write(payload, 0, payload.Length);
writer.Close();
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream s;
s = response.GetResponseStream();
string StrDate = "";
string strValue = "";
byte[] tt = StreamToBytes(s);
System.IO.File.WriteAllBytes(System.Web.HttpContext.Current.Server.MapPath("Upload/1.png"), tt);
// xiaochengxuma("");
}
/// <summary>
/// 小程序二维码
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public string xiaochengxuma(string path)
{
// string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=*****&secret=***";
string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=****&secret=****";
//请求url以获取数据
string result = HttpService.Get(url);
//保存access_token,用于收货地址获取
LitJson.JsonData jd = LitJson.JsonMapper.ToObject(result);
string access_token = (string)jd["access_token"];
string _url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + access_token;
string strURL = _url;
System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
request.Method = "POST";
request.ContentType = "application/json;charset=UTF-8";
JsonData _data = new JsonData();
_data["path"] = "pages/ErWeiMa/ErWeiMa";//_data["path"] = "pages/index?query=1";
_data["width"] = "430";
string _jso = _data.ToJson();
//string paraUrlCoded = param;
byte[] payload;
//payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
payload = System.Text.Encoding.UTF8.GetBytes(_jso);
request.ContentLength = payload.Length;
Stream writer = request.GetRequestStream();
writer.Write(payload, 0, payload.Length);
writer.Close();
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream s;
s = response.GetResponseStream();
string StrDate = "";
string strValue = "";
byte[] tt = StreamToBytes(s);
//将流保存在c盘test.png文件下
System.IO.File.WriteAllBytes(System.Web.HttpContext.Current.Server.MapPath("Upload/1.png"), tt);
JavaScriptSerializer jss = new JavaScriptSerializer();
return jss.Serialize("");
}
public static byte[] StreamToBytes(Stream stream)
{
List<byte> bytes = new List<byte>();
int temp = stream.ReadByte();
while (temp != -1)
{
bytes.Add((byte)temp);
temp = stream.ReadByte();
}
return bytes.ToArray();
}