zoukankan      html  css  js  c++  java
  • 微信红包接口开发

    开源项目见:https://github.com/JeffreySu/WeiXinMPSDK

            public ActionResult SendRedPack()
            {
                string mchbillno = DateTime.Now.ToString("HHmmss") + TenPayV3Util.BuildRandomStr(28);
    
                string nonceStr = TenPayV3Util.GetNoncestr();
    RequestHandler packageReqHandler
    = new RequestHandler(null); packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 packageReqHandler.SetParameter("wxappid", AppId); //公众账号ID packageReqHandler.SetParameter("mch_id", MchId); //商户号 packageReqHandler.SetParameter("mch_billno", mchbillno); //填入商家订单号 packageReqHandler.SetParameter("nick_name", "提供方名称"); //提供方名称 packageReqHandler.SetParameter("send_name", "红包发送者名称"); //红包发送者名称 packageReqHandler.SetParameter("re_openid", "接受收红包的用户的openId"); //接受收红包的用户的openId packageReqHandler.SetParameter("total_amount", "100"); //付款金额,单位分 packageReqHandler.SetParameter("min_value", "100"); //最小红包金额,单位分 packageReqHandler.SetParameter("max_value", "100"); //最大红包金额,单位分 packageReqHandler.SetParameter("total_num", "1"); //红包发放总人数 packageReqHandler.SetParameter("wishing", "红包祝福语"); //红包祝福语 packageReqHandler.SetParameter("client_ip", Request.UserHostAddress); //调用接口的机器Ip地址 packageReqHandler.SetParameter("act_name", "活动名称"); //活动名称 packageReqHandler.SetParameter("remark", "备注信息"); //备注信息 string sign = packageReqHandler.CreateMd5Sign("key", Key); packageReqHandler.SetParameter("sign", sign); //签名
    //发红包需要post的数据 string data = packageReqHandler.ParseXML(); //发红包接口地址 string url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
    //本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中) string cert = @"F:apiclient_cert.p12";
    //私钥(在安装证书时设置) string password = MchId;
    ServicePointManager.ServerCertificateValidationCallback
    = new RemoteCertificateValidationCallback(CheckValidationResult); //调用证书 X509Certificate2 cer = new X509Certificate2(cert, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet); HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url); webrequest.ClientCertificates.Add(cer); webrequest.Method = "post"; byte[] postdatabyte = Encoding.UTF8.GetBytes(data); webrequest.ContentLength = postdatabyte.Length; Stream stream; stream = webrequest.GetRequestStream(); stream.Write(postdatabyte, 0, postdatabyte.Length); stream.Close(); HttpWebResponse httpWebResponse = (HttpWebResponse)webrequest.GetResponse(); StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()); string responseContent = streamReader.ReadToEnd(); return Content(responseContent); }

             private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
             {
                  if (errors == SslPolicyErrors.None)
                         return true;
                  return false;
             }

    
    
  • 相关阅读:
    Android开发之JSON数据发送与获取
    Layouts之TableLayout表格布局
    Layouts之GridLayout网格布局
    Android WiFi模块学习
    关于Fragment的讲解及适配
    hive 压缩全解读(hive表存储格式以及外部表直接加载压缩格式数据);HADOOP存储数据压缩方案对比(LZO,gz,ORC)
    Dynamics CRM SQL转化为FetchXML的在线转化工具
    Dynamics CRM 通过Odata创建及更新记录各类型字段的赋值方式
    shell命令执行hive脚本(hive交互,hive的shell编程)
    CRM 2013 Script Loading Deep Dive
  • 原文地址:https://www.cnblogs.com/rockchen/p/4484191.html
Copyright © 2011-2022 走看看