Exemplo n.º 1
0
        public static string GetSign(SortedDictionary <string, string> dic, string key)
        {
            string sign = "";

            foreach (var item in dic)
            {
                sign += item.Key + "=" + item.Value + "&";
            }
            Console.WriteLine(sign.Trim('&'));

            //加密Md5
            return(EasyPay.GetMD5(sign.Trim('&') + key));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //协议类参数
            string signType       = "MD5";
            string batchBizid     = "100000000001000";  //商户号
            string _input_charset = "gbk";
            string batchBiztype   = "00000";
            string batchDate      = DateTime.Now.ToString("yyyyMMdd");
            string batchVersion   = "00";
            int    RandomNum;


            //业务类参数
            Random MyRandom = new Random();

            RandomNum = MyRandom.Next(1001, 9999);
            string batchCurrnum = DateTime.Now.ToString("yyyyMMddHHmmss") + RandomNum;  //批次号

            //批次明细
            string Num      = DateTime.Now.ToString("yyyyMMddHHmmss"); //序号
            string RealName = "测试";                                    //姓名
            string Phone    = "13800138000";                           //电话
            string CardNum  = "6228910000000000000";                   //卡号
            string IdNum    = "110110197802180789";                    //身份证号
            string Bank     = "工商银行";                                  //银行
            string Money    = "0.01";                                  //金额

            //                   序号,        银行账户,       开户名,         开户行,   分行,支行,公/私, 金额,     币种,省,  市,    手机号,  证件类型, 证件号,用户协议号,商户订单号,备注
            string batchContent = Num + "," + CardNum + "," + RealName + "," + Bank + ",分行,支行,私," + Money + ",CNY,北京,北京," + Phone + ",身份证," + IdNum + ",,,";

            batchContent += "|" + Num + "," + CardNum + "," + RealName + "," + Bank + ",分行,支行,私," + Money + ",CNY,北京,北京," + Phone + ",身份证," + IdNum + ",,,";

            //生成签名
            string easypay_url = EasyPay.CreatPayUrlto(
                signType,
                batchBizid,
                _input_charset,
                batchBiztype,
                batchDate,
                batchVersion,
                batchCurrnum,
                batchContent
                );

            string newEasypay_url = "";

            string[] patten1 = easypay_url.Split('&');
            for (int i = 0; i < patten1.Length; i++)
            {
                if (patten1[i].IndexOf("batchContent") == -1)
                {
                    if (i == 0)
                    {
                        newEasypay_url += patten1[i];
                    }
                    else
                    {
                        newEasypay_url += "&" + patten1[i];
                    }
                }
                else
                {
                    newEasypay_url += "&batchContent=" + System.Web.HttpUtility.UrlEncode(EasyPay.RSAEncryption(batchContent), System.Text.Encoding.Default);
                }
            }
            string returnPayValue = PostDataGetHtml(newEasypay_url);

            if (returnPayValue.IndexOf("fail") > -1)
            {
                Console.WriteLine("失败");
            }
            else
            {
                Console.WriteLine("成功");
            }
        }