Beispiel #1
0
        /// <summary>
        /// 阿里大于发送短信
        /// </summary>
        /// <param name="to">接收人号码</param>
        /// <param name="smsparam">短信模板变量</param>
        /// <param name="smssignname">短信签名名称</param>
        /// <param name="tempcode">模板编号</param>
        /// <returns></returns>
        public bool AliSend(string to, string smsparam, string smssignname, string tempcode)
        {
            // 第一步:把字典按Key的字母顺序排序
            IDictionary <string, string> sortedParams        = BuildParms(to, smsparam, smssignname, tempcode);
            IEnumerator <KeyValuePair <string, string> > dem = sortedParams.GetEnumerator();

            // 第二步:把所有参数名和参数值串在一起
            StringBuilder query = new StringBuilder();

            query.Append(_app_secret);
            while (dem.MoveNext())
            {
                string key   = dem.Current.Key;
                string value = dem.Current.Value;
                if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                {
                    query.Append(key).Append(value);
                }
            }

            // 第三步:使用MD5/HMAC加密
            byte[] bytes;

            query.Append(_app_secret);
            MD5 md5 = MD5.Create();

            bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(query.ToString()));

            // 第四步:把二进制转化为大写的十六进制
            StringBuilder signres = new StringBuilder();

            for (int i = 0; i < bytes.Length; i++)
            {
                signres.Append(bytes[i].ToString("X2"));
            }

            string sign = signres.ToString();

            sortedParams["sign"] = sign;

            //把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode
            string strRequestData = AlipayCore.CreateLinkStringUrlencode(sortedParams, Encoding.UTF8);

            string result = WebHelper.GetRequestData(_url + "?" + strRequestData, "get");

            if (result.Contains("<success>true</success>"))
            {
                return(true);
            }
            else
            {
                logger.Error(result);
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 生成要请求给支付宝的参数数组
        /// </summary>
        /// <param name="sParaTemp">请求前的参数数组</param>
        /// <param name="code">字符编码</param>
        /// <returns>要请求的参数数组字符串</returns>
        private static string BuildRequestParaToString(Dictionary <string, string> sParaTemp, Encoding code)
        {
            //待签名请求参数数组
            Dictionary <string, string> sPara = new Dictionary <string, string>();

            sPara = BuildRequestPara(sParaTemp);

            //把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode
            string strRequestData = AlipayCore.CreateLinkStringUrlencode(sPara, code);

            return(strRequestData);
        }
Beispiel #3
0
        /// <summary>
        /// 生成App支付订单参数信息
        /// 老版:https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.wJXHY0&treeId=59&articleId=103563&docType=1
        /// 新版:https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.HHgJg3&treeId=193&articleId=105297&docType=1
        /// </summary>
        /// <param name="outTradeNo">业务单号</param>
        /// <param name="subject">支付标题</param>
        /// <param name="body">支付内容</param>
        /// <param name="totalFee">支付金额</param>
        /// <returns></returns>
        public static string GetPayString(string outTradeNo, string subject, string body, decimal totalFee)
        {
            try
            {
                #region 数据
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("app_id", AlipayConfig.App_ID);
                dic.Add("method", "alipay.trade.app.pay");
                dic.Add("sign_type", AlipayConfig.Sign_type);
                dic.Add("charset", "utf-8");
                dic.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                dic.Add("version", "1.0");
                dic.Add("notify_url", AlipayConfig.Notify_Url);
                #region biz_content
                Dictionary <string, string> biz = new Dictionary <string, string>();
                biz.Add("subject", subject);
                biz.Add("body", body);
                biz.Add("out_trade_no", outTradeNo);
                biz.Add("timeout_express", "30m");            //该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m。
                biz.Add("total_amount", totalFee.ToString()); //单元(元)
                biz.Add("seller_id", AlipayConfig.Seller);
                biz.Add("product_code", "QUICK_MSECURITY_PAY");
                #endregion
                dic.Add("biz_content", JsonConvert.SerializeObject(biz));

                //生成签名
                dic.Add("sign", AlipayCore.CreateSign(dic));
                #endregion
                return(AlipayCore.CreateLinkStringUrlencode(dic, Encoding.UTF8));
            }
            catch (Exception ex)
            {
                LogHelper.SaveFileLog("WxPayUtils.GetAppPayString", ex.Message);
            }
            return("");
        }
Beispiel #4
0
        /// <summary>
        /// 支付
        /// </summary>
        public ActionResult Pay()
        {
            string result = WebHelper.GetPostStr();
            NameValueCollection parmas = WebHelper.GetParmList(result);

            //支付类型,必填,不能修改
            string paymentType = "1";

            //服务器异步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数
            string notifyUrl = string.Format("{0}/appalipay/notify", BSPConfig.ShopConfig.SiteUrl);

            //收款支付宝帐户
            string sellerEmail = AlipayConfig.Seller;
            //合作者身份ID
            string partner = AlipayConfig.Partner;
            //交易安全检验码
            string key = AlipayConfig.Key;

            //商户订单号
            string outTradeNo = "hmk" + DateTime.Now.ToString("yyMMdd") + Randoms.CreateRandomValue(6, true);
            //订单名称
            string subject = BSPConfig.ShopConfig.SiteTitle;
            //付款金额
            string totalFee = double.Parse(parmas["totalFee"]).ToString();
            //订单描述
            string body = "话费套餐";



            Encoding e = Encoding.GetEncoding(AlipayConfig.AppInputCharset);

            //把请求参数打包成数组
            SortedDictionary <string, string> parms = new SortedDictionary <string, string>();

            parms.Add("app_id", "2016092001932731");
            parms.Add("method", "alipay.trade.app.pay");
            parms.Add("charset", AlipayConfig.AppInputCharset);
            parms.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            parms.Add("version", "1.0");
            parms.Add("notify_url", notifyUrl);


            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("partner", partner);
            dic.Add("seller_id", sellerEmail);
            dic.Add("out_trade_no", outTradeNo);
            dic.Add("subject", subject);
            dic.Add("body", body);
            dic["total_amount"]    = totalFee;
            dic["product_code"]    = "QUICK_MSECURITY_PAY";
            dic["timeout_express"] = "30m";
            parms.Add("biz_content", JsonHelper.StringDicToJson(dic));
            parms.Add("sign_type", AlipayConfig.AppSignType);

            string sign = AlipayRSAFromPkcs8.sign(AlipayCore.CreateLinkString(AlipayCore.FilterPara(parms)), AlipayConfig.PrivateKey, AlipayConfig.AppInputCharset);

            parms.Add("sign", sign);

            //parms.Add("sign", HttpUtility.UrlEncode(sign, e));

            //parms.Remove("biz_content");
            Dictionary <string, string> dicArray = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> temp in parms)
            {
                dicArray.Add(temp.Key, temp.Value);
            }

            //记录充值信息
            RechargeModel rech = new RechargeModel
            {
                Out_trade_no = outTradeNo,
                Account      = parmas["account"],
                SuiteId      = parmas["vossuiteid"],
                PlatForm     = "支付宝",
                Type         = int.Parse(parmas["type"]),
                Role         = int.Parse(parmas["role"])
            };
            bool addres = Recharge.AddRecharge(rech);

            if (!addres)
            {
                return(AjaxResult("error", "记录充值信息失败"));
            }

            //string content = JsonHelper.StringDicToJson(dicArray);
            //content = content.Substring(0, content.Length - 1) + ",\"biz_content\":" + JsonHelper.StringDicToJson(dic) + "}";
            string content = AlipayCore.CreateLinkStringUrlencode(AlipayCore.FilterAllPara(parms), Encoding.UTF8);

            return(AjaxResult("success", content));
        }