Esempio n. 1
0
        public static T ConvertDic <T>(Dictionary <string, object> dic)
        {
            T t = Activator.CreateInstance <T>();

            PropertyInfo[] properties = t.GetType().GetProperties();
            if (properties.Length > 0 && dic.Count > 0)
            {
                for (int i = 0; i < properties.Length; i++)
                {
                    if (dic.ContainsKey(properties[i].Name))
                    {
                        if (properties[i].PropertyType.IsEnum)
                        {
                            object value = Enum.ToObject(properties[i].PropertyType, dic[properties[i].Name]);
                            properties[i].SetValue(t, value, null);
                        }
                        else
                        {
                            properties[i].SetValue(t, RedPackClient.CheckType(dic[properties[i].Name], properties[i].PropertyType), null);
                        }
                    }
                }
            }
            return(t);
        }
Esempio n. 2
0
        public RedPackInfo GetRedpackInfo(string appId, string mch_id, string mch_billno, string partnerkey, string weixincertpath, string weixincertpassword)
        {
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("nonce_str", Utils.CreateNoncestr());
            payDictionary.Add("mch_billno", mch_billno);
            payDictionary.Add("mch_id", mch_id);
            payDictionary.Add("appid", appId);
            payDictionary.Add("bill_type", "MCHT");
            string value = SignHelper.SignPackage(payDictionary, partnerkey);

            payDictionary.Add("sign", value);
            string data = SignHelper.BuildXml(payDictionary, false);
            string text = "";

            try
            {
                text = RedPackClient.Send(weixincertpath, weixincertpassword, data, RedPackClient.QueryRedPackUrl);
            }
            catch (Exception ex)
            {
                text = ex.Message;
            }
            RedPackInfo result;

            if (!string.IsNullOrEmpty(text) && text.Contains("return_code"))
            {
                result = RedPackClient.ConvertDic <RedPackInfo>(RedPackClient.FromXml(text));
            }
            else
            {
                result = new RedPackInfo
                {
                    return_code = "FAIL",
                    return_msg  = text,
                    status      = ""
                };
            }
            return(result);
        }
Esempio n. 3
0
        public string SendRedpack(SendRedPackInfo sendredpack)
        {
            string        result        = string.Empty;
            PayDictionary payDictionary = new PayDictionary();

            payDictionary.Add("nonce_str", Utils.CreateNoncestr());
            if (sendredpack.EnableSP)
            {
                if (sendredpack.SendRedpackRecordID > 0)
                {
                    payDictionary.Add("mch_billno", sendredpack.Main_Mch_ID + DateTime.Now.ToString("yyyymmdd") + sendredpack.SendRedpackRecordID.ToString().PadLeft(10, '0'));
                }
                else
                {
                    payDictionary.Add("mch_billno", sendredpack.Main_Mch_ID + DateTime.Now.ToString("yyyymmdd") + DateTime.Now.ToString("MMddHHmmss"));
                }
                payDictionary.Add("mch_id", sendredpack.Main_Mch_ID);
                payDictionary.Add("sub_mch_id", sendredpack.Sub_Mch_Id);
                payDictionary.Add("wxappid", sendredpack.Main_AppId);
                payDictionary.Add("msgappid", sendredpack.Main_AppId);
            }
            else
            {
                if (sendredpack.SendRedpackRecordID > 0)
                {
                    payDictionary.Add("mch_billno", sendredpack.Mch_Id + DateTime.Now.ToString("yyyymmdd") + sendredpack.SendRedpackRecordID.ToString().PadLeft(10, '0'));
                }
                else
                {
                    payDictionary.Add("mch_billno", sendredpack.Mch_Id + DateTime.Now.ToString("yyyymmdd") + DateTime.Now.ToString("MMddHHmmss"));
                }
                payDictionary.Add("mch_id", sendredpack.Mch_Id);
                payDictionary.Add("wxappid", sendredpack.WXAppid);
                payDictionary.Add("nick_name", sendredpack.Nick_Name);
                payDictionary.Add("min_value", sendredpack.Total_Amount);
                payDictionary.Add("max_value", sendredpack.Total_Amount);
            }
            payDictionary.Add("send_name", sendredpack.Send_Name);
            payDictionary.Add("re_openid", sendredpack.Re_Openid);
            payDictionary.Add("total_amount", sendredpack.Total_Amount);
            payDictionary.Add("total_num", sendredpack.Total_Num);
            payDictionary.Add("wishing", sendredpack.Wishing);
            payDictionary.Add("client_ip", sendredpack.Client_IP);
            payDictionary.Add("act_name", sendredpack.Act_Name);
            payDictionary.Add("remark", sendredpack.Remark);
            string text = SignHelper.SignPackage(payDictionary, sendredpack.PartnerKey);

            payDictionary.Add("sign", text);
            string text2 = SignHelper.BuildXml(payDictionary, false);

            RedPackClient.Debuglog(text2, "_DebugRedPacklog.txt");
            string text3 = RedPackClient.Send(sendredpack.WeixinCertPath, sendredpack.WeixinCertPassword, text2, RedPackClient.SendRedPack_Url);

            RedPackClient.writeLog(payDictionary, text, RedPackClient.SendRedPack_Url, text3);
            if (!string.IsNullOrEmpty(text3) && text3.Contains("SUCCESS") && !text3.Contains("<![CDATA[FAIL]]></result_code>"))
            {
                result = "1";
            }
            else
            {
                Regex  regex = new Regex("<return_msg><!\\[CDATA\\[(?<code>(.*))\\]\\]></return_msg>");
                Match  match = regex.Match(text3);
                string empty = string.Empty;
                if (match.Success)
                {
                    result = match.Groups["code"].Value;
                }
            }
            return(result);
        }
Esempio n. 4
0
 public static string Send(string cert, string password, string data, string url)
 {
     return(RedPackClient.Send(cert, password, Encoding.GetEncoding("UTF-8").GetBytes(data), url));
 }