예제 #1
0
        /// <summary>
        /// 微信支付统一下单,订单失效时间是1小时10分钟
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private async Task <UnifiedorderResult> UnifiedOrderAsync(UnifiedOrderRequestDto request)
        {
            TenPayV3UnifiedorderRequestData data = new TenPayV3UnifiedorderRequestData(request.AppId, request.MerchantId, request.Body, request.OutTradeNo, request.TotalFee, "", request.NotifyUrl, Senparc.Weixin.TenPay.TenPayV3Type.JSAPI, request.OpenId, request.MerchantSecret, request.NonceStr, "WEB", DateTime.Now, DateTime.Now.AddHours(1).AddMinutes(10));

            data.SignType = "MD5";
            return(await TenPayV3.UnifiedorderAsync(data));
        }
예제 #2
0
        public async Task <(bool, GetH5PaymentBeforeResponseDto)> GetH5PaymentBeforeAsync(GetH5PaymentBeforeResquestDto requstDto)
        {
            //微信下单

            //随机字符串参数
            string nonceStr = WeChatUtils.GetRandomString(16, false, true, true, false, string.Empty);
            var    unifiedOrderRequestDto = new UnifiedOrderRequestDto
            {
                AppId          = PlatformSettings.CDClientAppId,
                MerchantId     = requstDto.MerchantId,
                Body           = requstDto.Body,
                OutTradeNo     = requstDto.OutTradeNo,
                TotalFee       = requstDto.TotalFee,  //支付金额,单位分
                NotifyUrl      = requstDto.NotifyUrl, //支付通知回调
                OpenId         = requstDto.OpenId,
                MerchantSecret = requstDto.MerchantSecret,
                NonceStr       = nonceStr
            };
            var unifiedRes = await UnifiedOrderAsync(unifiedOrderRequestDto);

            if (!unifiedRes.IsReturnCodeSuccess() || !unifiedRes.IsResultCodeSuccess())
            {
                var errMsg = new StringBuilder();
                errMsg.Append($"微信支付下单失败:return_msg-{unifiedRes.return_msg}|err_code-{unifiedRes.err_code}|err_code_des-{unifiedRes.err_code_des}");
                errMsg.Append($"{Environment.NewLine}at SenparcPayBiz.GetH5PaymentBeforeAsync({JsonConvert.SerializeObject(requstDto)})");
                Logger.Error(errMsg.ToString());
                return(false, null);
            }
            var result = new GetH5PaymentBeforeResponseDto
            {
                AppId     = unifiedOrderRequestDto.AppId,
                TimeStamp = WeChatUtils.GetTimestamp(),
                NonceStr  = unifiedOrderRequestDto.NonceStr,
                Package   = $"prepay_id={unifiedRes.prepay_id}",
                SignType  = "MD5"
            };

            result.Sign = TenPayV3.GetJsPaySign(
                unifiedOrderRequestDto.AppId,
                result.TimeStamp, result.NonceStr,
                result.Package,
                unifiedOrderRequestDto.MerchantSecret,
                "MD5");
            return(true, result);
        }