4、调用现金红包接口
#region 发送红包
bool fals = false; //记录发送红包是否成功
string xmlResult = null; //现金红包接口返回的xml
string certPath = null; //证书在服务器的物理位置
string data = null; //调用现金红包接口需要的数据
try
{
//创建支付应答对象
RequestHandler packageReqHandler = new RequestHandler(null);
//初始化
packageReqHandler.Init();
string nonceStr = TenPayV3Util.GetNoncestr(); //时间戳
//设置package订单参数
packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串,不长于32位
packageReqHandler.SetParameter("mch_billno", System.Configuration.ConfigurationManager.AppSettings["TenPayV3_MchId"] + model.JournalNumber);//商户订单号(每个订单号必须唯一)组成:mch_id+yyyymmdd+10位一天内不能重复的数字。接口根据商户订单号支持重入,如出现超时可再调用。
packageReqHandler.SetParameter("mch_id", System.Configuration.ConfigurationManager.AppSettings["TenPayV3_MchId"]); //微信支付分配的商户号
packageReqHandler.SetParameter("wxappid", System.Configuration.ConfigurationManager.AppSettings["TenPayV3_AppId"]);//微信分配的公众账号ID(企业号corpid即为此appId)。接口传入的所有appid应该为公众号的appid(在mp.weixin.qq.com申请的),不能为APP的appid(在open.weixin.qq.com申请的)。
packageReqHandler.SetParameter("send_name", "测试");//商户名称
packageReqHandler.SetParameter("re_openid", model.BankCard); //用户openid 接受红包的用户用户在wxappid下的openid
packageReqHandler.SetParameter("total_amount", Convert.ToInt32((decimal)(model.Amount * 100M)).ToString(CultureInfo.InvariantCulture)); //付款金额 单位分
packageReqHandler.SetParameter("total_num", "1"); //红包发放总人数
packageReqHandler.SetParameter("wishing", "测试红包"); //红包祝福语
packageReqHandler.SetParameter("client_ip", HttpContext.Current.Request.UserHostAddress);//Ip地址
packageReqHandler.SetParameter("act_name", "测试红包");//活动名称
packageReqHandler.SetParameter("remark", "测试红包"); //备注
string sign = packageReqHandler.CreateMd5Sign("key", System.Configuration.ConfigurationManager.AppSettings["TenPayV3_Key"]);
packageReqHandler.SetParameter("sign", sign); //签名
data = packageReqHandler.ParseXML();
certPath = Server.MapPath("~/") + System.Configuration.ConfigurationManager.AppSettings["certPath"];
xmlResult = Sendredpack(data, System.Configuration.ConfigurationManager.AppSettings["TenPayV3_MchId"],certPath);
var res = XDocument.Parse(xmlResult);
string return_code = res.Element("xml").Element("return_code").Value;
if ("SUCCESS".Equals(return_code))
{
string result_code = res.Element("xml").Element("result_code").Value;
if ("SUCCESS".Equals(result_code))
{
fals = true;
}
}
}
catch (Exception exception)
{
}
#endregion










