.net 微信會員卡介面
建立介面
protected void Page_Load(object sender, EventArgs e)
{
taosoftsweixin.WX.Access_token at = taosoftsweixin.WX.WeiXinHelper.GetAccess_token();
string url_Menu_Create = "https://api.weixin.qq.com/card/create?access_token=" + at.access_token;
string postData = createMenuDate();
string result = PostWebRequest(url_Menu_Create, postData);
}
public string PostWebRequest(string postUrl, string paramData)
{
string ret = string.Empty;
try
{
byte[] byteArray = Encoding.UTF8.GetBytes(paramData); //轉化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = "application/json";
webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);//寫入引數
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
}
catch (Exception ex)
{
}
return ret;
}
public string createMenuDate()
{
string postData = "{";
postData += "\"card\": {";
postData += "\"card_type\": \"MEMBER_CARD\",";
postData += "\"member_card\": {";
postData += "\"background_pic_url\": \"https://mmbiz.qlogo.cn/mmbiz/\",";
postData += "\"base_info\": {";
postData += "\"logo_url\": \"https://mmbiz.qlogo.cn/mmbiz_jpg/\",";
postData += "\"brand_name\": \"XXX\",";
postData += "\"code_type\": \"CODE_TYPE_BARCODE\",";
postData += "\"title\": \"會員卡\",";
postData += "\"color\": \"Color010\",";
postData += "\"notice\": \"使用時向服務員出示此會員卡\",";
postData += "\"service_phone\": \"0335-5300544\",";
postData += "\"description\": \"不可與其他優惠同享\",";
postData += "\"date_info\": {";
postData += "\"type\": \"DATE_TYPE_PERMANENT\"";
postData += "},";
postData += "\"sku\": {";
postData += "\"quantity\": 100000000";
postData += "},";
postData += "\"get_limit\": 1,";
postData += "\"use_custom_code\": false,";
postData += "\"can_give_friend\": true,";
postData += "\"custom_url_name\": \"會員卡中心\",";
postData += "\"custom_url\": \"http://xxxx\"";
postData += "},";
postData += "\"supply_bonus\": false,";
postData += "\"supply_balance\": false,";
postData += "\"prerogative\": \"會員專用\",";
postData += "\"wx_activate\": true,";
postData += "\"wx_activate_after_submit\": true,";
postData += "\"wx_activate_after_submit_url\": \"http://xxxx\"";
postData += "}";
postData += "}";
postData += "}";
return postData;
}
}
}
必填專案
protected void Page_Load(object sender, EventArgs e)
{
taosoftsweixin.WX.Access_token at = taosoftsweixin.WX.WeiXinHelper.GetAccess_token();
string url_Menu_Create = "https://api.weixin.qq.com/card/membercard/activateuserform/set?access_token=" + at.access_token;
string postData = createMenuDate();
string result = PostWebRequest(url_Menu_Create, postData);
}
public string PostWebRequest(string postUrl, string paramData)
{
string ret = string.Empty;
try
{
byte[] byteArray = Encoding.UTF8.GetBytes(paramData); //轉化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = "application/json";
webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);//寫入引數
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
}
catch (Exception ex)
{
}
return ret;
}
public string createMenuDate()
{
string postData = "{";
postData += "\"card_id\": \"XXX",";
postData += "\"required_form\": {";
postData += "\"can_modify\":false,";
postData += "\"common_field_id_list\": [";
postData += "\"USER_FORM_INFO_FLAG_NAME\",";
postData += "\"USER_FORM_INFO_FLAG_MOBILE\"";
postData += "]";
postData += "}";
postData += "}";
return postData;
}
}
}