接口说明
适用对象:直连商户 服务商 渠道商
请求URL:https://api.mch.weixin.qq.com/v3/marketing/favor/users/{openid}/coupons
请求方式:POST
频率限制:500/s
处理耗时:100ms
接口规则:https://wechatpay-api.gitbook.io/wechatpay-api-v3
代码:
public string SendDJQ(string openid)
{
string url = string.Format("https://api.mch.weixin.qq.com/v3/marketing/favor/users/{0}/coupons",openid);
string out_request_no = mch_id + DateTime.Now.ToString("yyyy-MM-DDTHH:mm:ssZ") + DateTime.Now.ToString("hhmms");//商户订单号 组成:mch_id+yyyymmdd+10位一天内不能重复的数字。
try
{
string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(new
{
stock_id = "15182297",//批次id
out_request_no = out_request_no,//单据号
appid = APPID,//公众账号id
stock_creator_mchid = mch_id//创建批次的商户号
});
HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url);
webrequest.Method = "post";
webrequest.ContentType = "application/json;charset=utf-8";
webrequest.Accept = "application/json";
byte[] postdatabyte = Encoding.UTF8.GetBytes(jsonParam);
webrequest.ContentLength = postdatabyte.Length;
Stream stream;
stream = webrequest.GetRequestStream();
stream.Write(postdatabyte, 0, postdatabyte.Length);
stream.Close();
using (var httpWebResponse = webrequest.GetResponse())
using (StreamReader responseStream = new StreamReader(httpWebResponse.GetResponseStream()))
{
String ret = responseStream.ReadToEnd();
string result = ret.ToString();
return result;
}
}
catch (Exception ex)
{
return ex.Message;
}
}
未加载证书。