예제 #1
0
        /// <summary>
        /// 构造 DeepLink。
        /// </summary>
        /// <param name="prepayId">预支付交易会话标识。</param>
        /// <returns>用于H5调用微信支付的 DeepLink。</returns>
        public static string BuildDeepLink(string prepayId)
        {
            string nonceStr  = Common.Extension.StringExtension.NewNonceStr(32);
            string timestamp = DateTime.Now.GetUnixTimestamp().ToString();

            #region 获得签名

            Dictionary <string, string> dic = new Dictionary <string, string>
            {
                { "appid", WeixinApp.DevConfig.AppID },
                { "noncestr", nonceStr },
                { "package", TradeType.WAP.ToString() },
                { "prepayid", prepayId },
                { "timestamp", timestamp }
            };

            //获取签名。
            string sign = ParamsSignerEx.GetSign(dic);

            #endregion

            StringBuilder sb1 = new StringBuilder();
            sb1.AppendFormat("appid={0}", dic["appid"]);
            sb1.AppendFormat("&noncestr={0}", dic["noncestr"]);
            sb1.AppendFormat("&package={0}", dic["package"]);
            sb1.AppendFormat("&prepayid={0}", dic["prepayid"]);
            sb1.AppendFormat("&sign={0}", sign);
            sb1.AppendFormat("&timestamp={0}", dic["timestamp"]);

            string string2 = HttpUtility.UrlEncode(sb1.ToString());
            return($"weixin://wap/pay?{string2}");
        }
예제 #2
0
        /// <summary>
        /// 获取微信支付模型对象。
        /// </summary>
        /// <param name="timestamp">生成签名的时间戳。</param>
        /// <param name="nonceStr">生成签名的随机串。</param>
        /// <param name="prepayId">预支付交易会话标识。</param>
        /// <returns>微信支付模型对象。</returns>
        public static WxChooseWXPayModel GetWxChooseWXPayModel(long timestamp, string nonceStr, string prepayId)
        {
            if (string.IsNullOrEmpty(nonceStr))
            {
                throw new ObjectNullException(nameof(nonceStr));
            }

            WxChooseWXPayModel model = new WxChooseWXPayModel()
            {
                Timestamp = timestamp,
                NonceStr  = nonceStr,
                Package   = $"prepay_id={prepayId}"
            };

            Dictionary <string, string> dic = new Dictionary <string, string>
            {
                { "appId", WeixinApp.DevConfig.AppID },
                { "timeStamp", model.Timestamp.ToString() },
                { "nonceStr", model.NonceStr },
                { "package", model.Package },
                { "signType", model.SignType }
            };

            model.PaySign = ParamsSignerEx.GetSign(dic);
            return(model);
        }
예제 #3
0
        public void GetSignTest()
        {
            Dictionary <string, string> dic = new Dictionary <string, string>
            {
                { "p1", "p1" },
                { "p2", "p2" }
            };

            string sign = ParamsSignerEx.GetSign(dic);

            Assert.Equal("FA51F2AE815D49B03340352D71775C53", sign);
        }