Example #1
0
        //public override DApiResult<string> Pay(long orderNo, decimal price, string subject)
        //{
        //    var dict = Config.BaseParams("alipay.trade.pay");
        //    //业务参数
        //    var item = new Dictionary<string, object>
        //    {
        //        {"out_trade_no", orderNo},
        //        {"product_code", "QUICK_MSECURITY_PAY"},
        //        {"auth_code", "28763443825664394"},
        //        {"subject", subject},
        //        {"total_amount", price}
        //    };
        //    dict.Add("biz_content", JsonHelper.ToJson(item));
        //    dict.Add("sign", dict.RsaSign(Config.PrivateKey, Config.Charset));

        //    var url = $"{Config.Gateway}?{dict.ParamsUrl()}";
        //    Logger.Info(JsonHelper.ToJson(dict, indented: true));
        //    using (var http = new HttpHelper(url, Encoding.GetEncoding(Config.Charset)))
        //    {
        //        var html = http.GetHtml();
        //        Logger.Info(html);
        //        var dto = JsonHelper.Json<ReturnAlipayDto>(html);
        //        if (dto?.alipay_trade_pay_response == null)
        //            return DApiResult.Error<string>("支付接口异常");
        //        var result = dto.alipay_trade_pay_response;
        //        if (result.code != "10000")
        //            return DApiResult.Error<string>($"{result.msg}:{result.sub_msg}");
        //        return DApiResult.Succ(string.Empty);
        //    }
        //}

        public override DResult<VerifyDto> Verify()
        {
            var paramDict = OnlinePayHelper.GetParams();
            Logger.Info(JsonHelper.ToJson(paramDict, indented: true));
            var signVerified = AlipaySignature.RsaCheck(paramDict, Config.PublicKey, Config.Charset);
            if (!signVerified) return DResult.Error<VerifyDto>("验证签名失败");
            if (paramDict.GetValue<string>("app_id") != Config.AppId)
                return DResult.Error<VerifyDto>("AppId异常");
            var dto = new VerifyDto
            {
                Id = paramDict.GetValue<string>("out_trade_no"),
                TradeNo = paramDict.GetValue<string>("trade_no"),
                TradeStatus = paramDict.GetValue<string>("trade_status"),
                Amount = paramDict.GetValue<decimal>("total_amount"),
                BuyerId = paramDict.GetValue<string>("buyer_id"),
                BuyerAccount = paramDict.GetValue<string>("buyer_logon_id")
            };
            return DResult.Succ(dto);
        }
Example #2
0
 public override DResult<VerifyDto> Verify()
 {
     var paramDict = OnlinePayHelper.GetParams();
     Logger.Info(JsonHelper.ToJson(paramDict, indented: true));
     var sign = paramDict.GetValue<string>("sign");
     var checkSign = paramDict.Md5Sign(Config.PrivateKey);
     if (sign != checkSign)
         return DResult.Error<VerifyDto>("验证签名失败");
     if (Config.AppId != paramDict.GetValue<string>("appid"))
         return DResult.Error<VerifyDto>("AppId异常");
     var dto = new VerifyDto
     {
         Id = paramDict.GetValue<string>("out_trade_no"),
         TradeNo = paramDict.GetValue<string>("transaction_id"),
         TradeStatus = paramDict.GetValue<string>("result_code"),
         Amount = paramDict.GetValue<decimal>("total_fee"),
         BuyerId = paramDict.GetValue<string>("openid")
     };
     return DResult.Succ(dto);
 }