changwen313 2017-12-11 13:13 采纳率: 100%
浏览 1380
已结题

.net 微信红包程序写死openid的情况下,发第一次红包正常,再发用户就收不到任何东西了。请指教

.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 "";

    }

}

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-12-12 01:23
    关注

    CreateRandomCode
    实现代码在哪里,是随机的么

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题