コード例 #1
0
        public RedpackResponse SendRedpack(RedpackRequest request)
        {
            try
            {
                SortedDictionary <String, String> param = new SortedDictionary <String, String>();
                String noncestr  = CommonUtil.CreateNoncestr();
                String timeStamp = CommonUtil.GetTimestamp().ToString();
                if (timeStamp.Length >= 10)
                {
                    timeStamp = timeStamp.Substring(timeStamp.Length - 10);
                }
                else
                {
                    timeStamp = timeStamp.PadLeft(10, '0');
                }
                var    mchId  = isSubCommercial ? Config.SubPartnerId : Config.PartnerId;
                string billno = mchId + DateTime.Now.ToString("yyyyMMdd") + timeStamp;
                param.Add("nonce_str", noncestr);
                param.Add("mch_billno", billno);
                param.Add("mch_id", mchId);
                param.Add("wxappid", appid);
                param.Add("send_name", request.SendName);
                param.Add("re_openid", request.OpenId);
                param.Add("total_amount", (request.Amount * 100).ToString());
                param.Add("total_num", "1");
                param.Add("wishing", request.Wishing);
                param.Add("client_ip", request.ClientIP);
                param.Add("act_name", request.ActivityName);
                param.Add("remark", request.Remark);
                String tmpPackageStr = CommonUtil.CreateLinkString(param);
                String signValue     = CommonUtil.Sign(tmpPackageStr, Config.PartnerKey);
                param.Add("sign", signValue);

                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                X509Certificate cer = new X509Certificate(Config.CertFilePath, mchId, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);

                String tmpRes    = HttpRequestUtil.Send("POST", RedpackUrl, CommonUtil.ArrayToXml(param), 10, cer);
                var    tmpResult = XmlToDic(tmpRes);
                if (tmpResult["return_code"] == Fail)
                {
                    return(new RedpackResponse
                    {
                        RetCode = Fail,
                        RetMsg = tmpResult["return_msg"]
                    });
                }

                if (tmpResult["result_code"] == Fail)
                {
                    var errMsg = "";
                    if (!tmpResult.TryGetValue("err_code_des", out errMsg))
                    {
                        errMsg = GetErrMsg(tmpResult["err_code"]);
                    }

                    return(new RedpackResponse
                    {
                        RetCode = Fail,
                        RetMsg = errMsg
                    });
                }

                return(new RedpackResponse
                {
                    SendListId = tmpResult["send_listid"]
                });
            }
            catch (Exception ex)
            {
                return(new RedpackResponse
                {
                    RetCode = Fail,
                    RetMsg = ex.Message
                });
            }
        }
コード例 #2
0
 /// <summary>
 /// 发送现金红包
 /// </summary>
 /// <param name="request">红包请求类</param>
 /// <returns></returns>
 public abstract RedpackResponse SendRedpack(RedpackRequest request);
コード例 #3
0
ファイル: WeiXinHandler.cs プロジェクト: gonghaimin/weixin
 public override RedpackResponse SendRedpack(RedpackRequest request)
 {
     return(weixin.SendRedpack(request));
 }