예제 #1
0
        public override Task <UnifiedOrderReturnModel> Unifiedorder(string OrderId, string Paytype, decimal Totalfee, string Ip, string Body, string Attach)
        {
            UnifiedOrderReturnModel      unifiedorderReturn = new UnifiedOrderReturnModel();
            IDictionary <string, string> dic = new SortedDictionary <string, string>();
            string channel = "alipay";

            switch (Paytype)
            {
            case "1":    //网银
                channel = "unipay";
                break;

            case "21":                 //支付宝转卡
                channel = "aliToCard"; // "alipay";
                break;

            case "14":    //支付宝扫码
                channel = "bmAlipay";
                break;

            case "2":    //支付宝H5
                channel = "alipay";
                break;

            default:
                channel = "unipay";
                break;
            }
            dic.Add("rid", this.MchID);
            dic.Add("channel", channel);
            dic.Add("price", Totalfee.ToString("F2"));
            dic.Add("user_id", new Random().Next(1000, 9999).ToString());
            dic.Add("notify_url", this.NotifyUrl);
            dic.Add("out_order_sn", OrderId);
            string signstr = PayHelper.GetParamSrc(dic);

            signstr = string.Format("krid={0}&{1}&kts={2}", this.MchID, signstr, PayHelper.GenerateTimeStamp());
            string sign = PayHelper.Md5Hash4(signstr);

            sign = PayHelper.Md5Hash4(sign + this.MchKey);
            dic.Add("sign", sign);
            dic.Add("kts", PayHelper.GenerateTimeStamp());
            dic.Add("krid", this.MchID);
            string  response = HttpHelper.Post(this.Plat.Pay_gateway, JsonConvert.SerializeObject(dic));
            dynamic jo       = JsonConvert.DeserializeObject(response);
            string  resCode  = jo["errno"];

            if (resCode == "0")
            {
                string url = jo["data"]["pay_link"];
                unifiedorderReturn.Type         = PayReturnTypeEnum.Url;
                unifiedorderReturn.Content      = url;
                unifiedorderReturn.OrderNumber  = OrderId;
                unifiedorderReturn.SerialNumber = OrderId;
                unifiedorderReturn.RealPrice    = Totalfee.ToString("F2");
            }
            else
            {
                unifiedorderReturn.Type         = PayReturnTypeEnum.Err;
                unifiedorderReturn.Content      = "第三方下单失败";
                unifiedorderReturn.OrderNumber  = OrderId;
                unifiedorderReturn.SerialNumber = OrderId;
                unifiedorderReturn.RealPrice    = Totalfee.ToString("F2");
            }
            return(Task.FromResult <UnifiedOrderReturnModel>(unifiedorderReturn));
            //return new Task<UnifiedorderReturn>(() => unifiedorderReturn);
        }