Exemple #1
0
        /// <summary>
        /// Gets prepay_id from wechat payment
        /// </summary>
        /// <param name="config"></param>
        /// <param name="openId"></param>
        /// <param name="out_trade_no"></param>
        /// <param name="body"></param>
        /// <param name="clientIp"></param>
        /// <param name="totalFee"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string GetPrepayId(WeChatPayConfig config, string openId, string out_trade_no, string body, string clientIp, int totalFee, TradeType type)
        {
            string          prepayId = string.Empty;
            BaseResponse    response = null;
            PreOrderRequest request  = new PreOrderRequest(config);

            request.out_trade_no     = out_trade_no;
            request.spbill_create_ip = clientIp;
            request.total_fee        = totalFee;
            request.trade_type       = type;
            request.body             = body;
            request.detail           = body;
            request.openid           = openId;
            response = request.Execute();
            if (response != null)
            {
                prepayId = ((PreOrderResponse)response).prepay_id;
            }
            return(prepayId);
        }
Exemple #2
0
        /// <summary>
        /// JSSDK Payment configure signature
        /// </summary>
        /// <param name="config"></param>
        /// <param name="nancestr"></param>
        /// <param name="timestamp"></param>
        /// <param name="url"></param>
        /// <param name="ticket"></param>
        /// <returns></returns>
        public static string GetJsApiPayConfigSign(WeChatPayConfig config, string nancestr, string timestamp, string url, JSAPITicket ticket)
        {
            string sign = null;
            SortedDictionary <string, string> param = new SortedDictionary <string, string>();

            if (ticket == null || string.IsNullOrEmpty(ticket.Ticket))
            {
                throw new Exception("WeChat js ticket is empty.");
            }
            logger.Info("Generate pay config sign");
            logger.Info("jsapi_ticket:" + ticket.Ticket);
            logger.Info("timestamp:" + timestamp);
            logger.Info("noncestr:" + nancestr);
            logger.Info("url:" + url);

            param.Add("jsapi_ticket", ticket.Ticket);
            param.Add("timestamp", timestamp);
            param.Add("noncestr", nancestr);
            param.Add("url", url);
            sign = HashWrapper.SHA1_Hash(param);
            logger.Info("sign:" + sign);
            return(sign);
        }
Exemple #3
0
        public static AccessToken GetWeChatToken(WeChatPayConfig config, AccessToken oldToken, out bool changed)
        {
            changed = false;
            AccessToken  token   = null;
            TokenRequest request = null;
            bool         needGet = false;

            if (oldToken == null)
            {
                needGet = true;
            }
            else
            {
                if (oldToken.ExpiresTime < DateTime.Now)
                {
                    needGet = true;
                }
            }

            if (needGet)
            {
                request = new TokenRequest(config);
                BaseResponse res = request.Execute();
                if (res != null)
                {
                    changed = true;
                    AccessTokenResponse tokenRes = (AccessTokenResponse)res;
                    if (tokenRes.Access_Token != null)
                    {
                        token    = tokenRes.Access_Token;
                        oldToken = token;
                    }
                }
            }
            return(token);
        }
Exemple #4
0
        public string GetJsApiPaySign(WeChatPayConfig config, SortedDictionary <string, string> param)
        {
            string sign = null;

            return(sign);
        }