Ejemplo n.º 1
0
        public static WxPayData GenerateUnifiedWxPayData(this TopupContext context, string mchid, string outTradeNo, string payKey)
        {
            var data = new WxPayData();

            data.Body           = "会员卡充值";
            data.Attach         = "attach";
            data.OutTradeNo     = outTradeNo;
            data.TimeStart      = DateTime.Now.ToString("yyyyMMddHHmmss");
            data.TimeExpire     = DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"); //"20180905091412"; //
            data.AppId          = context.AppId;                                          //Constants.WxConfig.AppId;
            data.OpenId         = context.OpenId;
            data.TradeType      = "JSAPI";
            data.GoodsTag       = "会员卡充值";
            data.MchId          = mchid;
            data.Totalfee       = context.Money * 100;
            data.NotifyUrl      = "https://www.yourc.club/api/enjoy/PayNotify";
            data.SpbillCreateIp = "118.24.139.228";
            data.NonceStr       = RandomGenerator.Instance.Genernate();
            data.SignType       = WxPayData.SIGN_TYPE_HMAC_SHA256;
            //data.SceneInfo = "";
            data.Sign = data.MakeSign(payKey);
            //data.ProductId = "12235413214070356458058";
            //data.SceneInfo = "";
            if (data.WithRequired(out string errMsg) == false)
            {
                throw new WxPayException(errMsg);
            }
            return(data);
        }
Ejemplo n.º 2
0
 public PullWxPayData GenerateUnifiedorderforTopup(TopupContext context)
 {
     Guard.ArgumentNotNull(context, "context");
     Guard.ArgumentNotNullOrEmpty(
         new string[] { context.MCode, context.CardId, context.UserCode },
         new string[] { "MCode", "CardId", "UserCode" }
         );
     return(client.GenerateUnifiedorder(context));
 }
Ejemplo n.º 3
0
        public Trade PrepareUnifiedorder(TopupContext context, out WxPayAttach attach)
        {
            var queryString = $@"
    INSERT INTO 
    [dbo].[Trade]([MerchantId],[WxUserId],[TradeCode],[WxOrderId],[TradeId],[TradeType],
[TradeState],[Money],[RealMoney],[CreatedDateTime],[Attach], [Strategy])
    VALUES( 
    @pMerhantId,
    (SELECT TOP 1 [WxUserId] FROM [dbo].[WxUserIdentity] WHERE AppId=@pAppId AND OpenId=@pOpenId ) AS WxUserId,
    (SELECT COUNT(Id) + 1 FROM [dbo].[Trade] WHERE CreatedDateTime / 86400 * 86400 = CONVERT(BIGINT,DATEDIFF(S,'1970-01-01',SYSDATETIME())) / 86400 * 86400) AS [TradeCode],
    @pWxOrderId AS WxOrderId,
    @pTradeId AS TradeId,
    {(int)TradeTypes.Recharge} AS TradeType,
    {(int)TradeStates.HavePay} AS TradeState,
    @pMoney AS Money,
    @pRealMoney AS RealMoney,
    DATEDIFF(S,'1970-01-01',SYSUTCDATETIME()) AS CreatedDateTime,
    @pAttach AS Attach,
    @pStrategy AS Strategy);
    UPDATE [dbo].[Trade] SET TradeId=CONCAT(@prefix , [dbo].[funLpad](Id,10,'0')) WHERE WxOrderId = @pWxOrderId;
    SELECT TOP 1 *  FROM [dbo].[Trade] WHERE WxOrderId = @pWxOrderId;
";

            //var pyramid = this.wxUserService.GetSharedContext(context as IWxUserKey)
            //    .BuildSharedPyramid(context as IWxUserKey, out long basicWxUserId);
            attach = new WxPayAttach()
            {
                CardId    = context.CardId,
                NonceStr  = this.generator.Genernate(),
                TimeStamp = DateTime.UtcNow.ToUnixStampDateTime(),
                UserCode  = context.UserCode,
                MCode     = context.MCode
            };
            context.Money = context.Money * 100;
            attach.Sign(context.Money);
            using (var database = this.databaseFactory.GenerateDatabase(isWriteOnly: true))
            {
                return(database.SqlQuerySingleOrDefaultTransaction <Trade>(queryString, new
                {
                    @pAppId = context.AppId,
                    @pMerhantId = context.MerchantId,
                    @pOpenId = context.OpenId,
                    @pWxOrderId = Guid.NewGuid().ToString().Replace("-", string.Empty),
                    @pTradeId = Guid.NewGuid().ToString().Replace("-", string.Empty),
                    @pMoney = context.Money,
                    @pRealMoney = context.Money + (context.Money * 0.2),
                    @pStrategy = "{}",
                    @pAttach = attach.SerializeToJson(),
                    @prefix = string.Format("T{0}", DateTime.UtcNow.ToString("yyyyMMdd"))
                }));
            }
        }
Ejemplo n.º 4
0
 public static TradeDetails Generate(this TopupContext context, string mchid)
 {
     return(new TradeDetails()
     {
         CreatedTime = DateTime.Now.ToUnixStampDateTime(),
         AppId = context.AppId,
         OpenId = context.OpenId,
         CardId = context.CardId,
         Code = context.Code,
         MchId = mchid,
         OrderId = Guid.NewGuid().ToString().Replace("-", string.Empty),
         State = TradeStates.Waiting,
         Money = context.Money * 100,
         RealMoeny = context.Money * 100 + (int)(context.Money * 100 * 0.2),
         Type = TradeTypes.Recharge
     });
 }
Ejemplo n.º 5
0
        public PullWxPayData GenerateUnifiedorder(TopupContext context)
        {
            ////P3 Need to query from cache.
            var payment  = this.weChatPayService.GetPayment(context.AppId);
            var merchant = this.sharingHostService.MerchantDetails.FirstOrDefault(o => o.MCode.Equals(context.MCode));

            context.MerchantId = merchant.Id;
            var trade = this.weChatPayService.PrepareUnifiedorder(context, out WxPayAttach attach);
            var data  = context.GenerateUnifiedWxPayData(
                payment.MchId.ToString(),
                trade.TradeId,
                payment.PayKey,
                attach.NonceStr,
                attach.Paysign);

            return(GenernatePullWxPayData(trade, data, payment.MchId.ToString(), payment.PayKey));
        }
Ejemplo n.º 6
0
        public static WxPayData GenerateUnifiedWxPayData(
            this TopupContext context,
            string mchid,
            string outTradeNo,
            string payKey,
            string noceStr,
            string signature)
        {
            var data = new WxPayData()
            {
                AppId          = context.AppId,
                TimeStart      = DateTime.Now.ToString("yyyyMMddHHmmss"),
                TimeExpire     = DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"), //"20180905091412"; //
                Body           = "会员卡充值",
                Attach         = signature,
                OutTradeNo     = outTradeNo,
                GoodsTag       = "会员卡充值",
                TradeType      = "JSAPI",
                MchId          = mchid,
                Totalfee       = context.Money,
                NotifyUrl      = "https://www.yourc.club/api/sharing/PayNotify",
                SpbillCreateIp = "118.24.139.228",
                NonceStr       = noceStr,
                SignType       = WxPayData.SIGN_TYPE_HMAC_SHA256,
                OpenId         = context.OpenId
                                 //   SceneInfo = "{'h5_info': {'type':'Miniprogarm','app_name': '利群奶茶店','package_name': 'com.tencent.tmgp.sgame'}}"
            };

            data.Sign = data.MakeSign(payKey);

            if (data.WithRequired(out string errMsg) == false)
            {
                throw new WeChatPayException(errMsg);
            }
            return(data);
        }