Exemple #1
0
        private string CreatePayPackageAndGetPackageXml(PayInputModel payInput, string nonceStr)
        {
            int total_fee = Convert.ToInt32(payInput.TotalAmount * 100);
            //****************************************************************获取预支付订单编号***********************
            PackageParamModel packageDic = new PackageParamModel();

            packageDic.AddValue("appid", this.AppId);                                   //应用ID
            packageDic.AddValue("mch_id", this._mchId);                                 //商户号
            packageDic.AddValue("nonce_str", nonceStr);                                 //随机字符串
            packageDic.AddValue("body", payInput.Body);                                 //商品描述 String(128) 做二次支付的时候订单号不能重复 如果要重复 第二次和第一次的商品描述要一样   package.Add("detail",body);//商品详细
            packageDic.AddValue("out_trade_no", payInput.OrderId);                      //商户订单号
            packageDic.AddValue("total_fee", total_fee);                                //支付总金额
            packageDic.AddValue("spbill_create_ip", WebHelper.GetRemoteIpAddress());    //终端IP
            packageDic.AddValue("notify_url", this._notifyUrl);                         //通知地址
            packageDic.AddValue("trade_type", payInput.TradeType.GetEnumDescription()); //交易类型 小程序使用此类型
            packageDic.AddValue("fee_type", "CNY");                                     //币种,人民币
            packageDic.AddValue("attach", payInput.Attach);                             //自定义参数
            if (payInput.TradeType == TradeType.JSAPI)
            {
                if (payInput.OpenId.IsNullOrEmpty())//用户标识JSAPI毕传
                {
                    throw new WxPayException("JSAPI必须指定OpenId");
                }
            }
            if (!payInput.OpenId.IsNullOrEmpty())
            {
                packageDic.AddValue("openid", payInput.OpenId);
            }
            var paySign = WechatCommonUtlis.GetMD5Sign(packageDic, this._appKey);//使用Md5签名

            packageDic.AddValue("sign", paySign);
            return(packageDic.ToXml());
        }
        public async Task <Result> PayAsync(PayInputModel input)
        {
            try
            {
                var payment = new Data.Models.Payment
                {
                    OrderId    = input.OrderId,
                    TotalPrice = input.TotalPrice
                };

                var messageData = new PaymentCompletedMessage
                {
                    OrderId = payment.OrderId
                };

                var message = new Message(messageData);

                await this.SaveAsync(payment, message);

                await this.publisher.Publish(messageData);

                await this.MarkMessageAsPublished(message.Id);

                return(Result.Success);
            }
            catch (Exception e)
            {
                var errorMessage = "Failed to save order";

                this.logger.LogError(e, errorMessage);

                return(Result.Failure(new[] { errorMessage }));
            }
        }
Exemple #3
0
        /// <summary>
        /// JsApiUnified统一下单  JSAPI一般用于微信浏览器内支付 用于公众号和小程序
        /// </summary>
        /// <param name="payInput"></param>
        /// <returns></returns>
        public async Task <PayReturnModel> SubmitUnifiedOrderPay(PayInputModel payInput)
        {
            string unifiedorderPayUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";//统一支付地址
            string nonceStr           = WechatCommonUtlis.GetNonceStr();
            var    xmlPackage         = this.CreatePayPackageAndGetPackageXml(payInput, nonceStr);
            string xmlResult          = await WebHelper.HttpPostAsync(unifiedorderPayUrl, xmlPackage, null, 10);

            return(CreatePayReturnModel(payInput.TradeType, nonceStr, xmlResult));
        }