.net之前写的微信红包的程序,调试的时候第一次红包正常发送,再次运行程序,用户端没有收到红包,
不知道是什么情况.将return reader.ReadToEnd()打印出来是红包参数里付款金额total amount的值。
请问下这是什么情况?我发的是1元的红包,应该不存在红包上线的问题,请大神指点我。
以下是源码
using System;
using System.Collections.Generic; //Dictionary需要引用他,默认的程序是应用他的。
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography;
using System.IO;
using System.Collections; //Hashtable
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
//随机字符串
string nonce_str = Class1.CreateRandomCode(32);
//商户号
string mch_id = "xxxxx";
//商户订单号
string mch_billno = mch_id + DateTime.Now.ToString("yyyyMMdd") + Class1.Rand();//自己生成把
//公众账号appid
string wxappid = "xxxx";
//提供方名称
string nick_name = "提供方名称";
//商户名称
string send_name = "xxxxx";
//用户openid
string re_openid = "xxxxx";
//付款金额 这里要注意 提现是 1 - 200元 ,但是这里的单位是 “分”
string total_amount = (1 * 100).ToString();
//最小红包金额
string min_value = (1 * 100).ToString();
//最大红包金额
string max_value = (1 * 100).ToString();
//红包发放总人数
string total_num = "1";
//红包祝福语
string wishing = "幸运红包";
string client_ip = "xxxxx";
//活动名称
string act_name = "幸运红包";
//备注
string remark = "提现问题,请联系客服人员";
Dictionary<string,string> parameters = new Dictionary<string,string>();
parameters.Add("act_name", act_name);
parameters.Add("client_ip", client_ip);
parameters.Add("min_value", min_value);
parameters.Add("max_value", max_value);
parameters.Add("mch_billno", mch_billno);
parameters.Add("mch_id", mch_id);
parameters.Add("nonce_str", nonce_str);
parameters.Add("nick_name", nick_name);
parameters.Add("re_openid", re_openid);
parameters.Add("remark", remark);
parameters.Add("send_name", send_name);
parameters.Add("total_num", total_num);
parameters.Add("total_amount", total_amount);
parameters.Add("wishing", wishing);
parameters.Add("wxappid", wxappid);
//生成签名
string sign = Class1.CreateSignString(parameters, "Qwertyuiopasdfghjklzxcvbnm098765");
parameters.Add("sign", sign);
string sendxml = "<xml>";
foreach (KeyValuePair<string,string> pair in parameters)
{
sendxml += "<" + pair.Key + ">" + "<![CDATA["+pair.Value+"]]></" + pair.Key + ">";
}
sendxml += "</xml>";
Class1 ojb = new Class1();
ojb.OpenReadWithHttps(url, sendxml, "UTF-8");
}
}
public class Class1
{
public string OpenReadWithHttps(string URL, string strPostdata, string strEncoding)
{
try
{
Encoding encoding = Encoding.UTF8;
string cert = @"D:\cert\apiclient_cert.p12";
string password = "xxxx";//这里是填写的是 微信支付商户号
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
X509Certificate cer = new X509Certificate(cert, password);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.ClientCertificates.Add(cer);
request.Method = "post";
request.Accept = "text/html, application/xhtml+xml, */*";
//request.ContentType = "application/x-www-form-urlencoded";
request.ContentType = "text/xml";
byte[] buffer = encoding.GetBytes(strPostdata);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding(strEncoding)))
{
return reader.ReadToEnd();
}
}
catch (Exception e)
{
System.IO.File.WriteAllText(@"C:\zcw.log", e.Message, System.Text.Encoding.UTF8);
return "";
}
}