示例#1
0
        /// <summary>
        /// 传入 OpenId,订单Id,金额(分),过期时间(20141010121314),商品名称。
        /// </summary>
        /// <returns></returns>
        public static string CreateJSAPIPayJson(PayParam param)
        {
            if (param.TotalFee == null || string.IsNullOrWhiteSpace(param.ProductName) || string.IsNullOrWhiteSpace(param.OrderNumber) || string.IsNullOrWhiteSpace(param.OpenId) || string.IsNullOrWhiteSpace(param.TimeExpire))
            {
                return("参数错误");
            }
            param.TradeType = EnumHelper.TradeType.JSAPI;
            var result = GetUnifiedOrder(param);
            //LogHelper.WriteLog("aa_", "GetUnifiedOrder后的值是:" + result);
            var xe = XElement.Parse(result, LoadOptions.SetLineInfo);

#warning 这里暂时使用了 redis的Common
            try
            {
                var prepayId = xe.GetElement("prepay_id").Value;
                var payReq   = new RequestHandler();
                payReq.SetKey(GetConfig.GetKey(param));
                payReq.SetParameter("appId", GetConfig.GetAppid(param));
                payReq.SetParameter("timeStamp", PayUtil.GetTimestamp());
                payReq.SetParameter("nonceStr", PayUtil.GetNoncestr());
                payReq.SetParameter("package", "prepay_id=" + prepayId);
                payReq.SetParameter("signType", "MD5");
                //创建签名
                payReq.SetParameter("paySign", payReq.CreateMd5Sign());
                var payReqXml  = payReq.ParseXml();
                var payReqJson = payReq.ParseJson();
                return(payReqJson);
            }
            catch (Exception)
            {
                var returnCode = xe.GetElement("return_code").Value;
                var returnMsg  = xe.GetElement("return_msg").Value;
                return("{Error:'" + returnCode + returnMsg + "'}");
            }
        }
示例#2
0
 /// <summary>
 /// 必须传入Debug,Url,可选传入:WeChatPublic
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public string CreateWxConfig(WeChatParam param)
 {
     try
     {
         var noncestr    = PayUtil.GetNoncestr();
         var timestamp   = PayUtil.GetTimestamp();
         var jsapiTicket = Token.GetJsapiTicket(param);
         var appId       = GetConfig.GetAppid(param);
         var packageReq  = new RequestHandler();
         packageReq.SetParameter("noncestr", noncestr);
         packageReq.SetParameter("jsapi_ticket", jsapiTicket);
         packageReq.SetParameter("timestamp", timestamp);
         packageReq.SetParameter("url", param.Url);
         var signature = packageReq.CreateSHA1Sign();
         // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
         // 必填,公众号的唯一标识
         // 必填,生成签名的时间戳
         // 必填,生成签名的随机串
         // 必填,签名,见附录1
         // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
         var result = "wx.config({debug:" + (param.Debug ? "true" : "false") + ", appId: '" + appId + "', timestamp: " + timestamp + ", nonceStr: '" + noncestr + "', signature: '" + signature + "',jsApiList: ['checkJsApi','onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','hideMenuItems','showMenuItems','hideAllNonBaseMenuItem','showAllNonBaseMenuItem','translateVoice','startRecord','stopRecord','onRecordEnd','playVoice','pauseVoice','stopVoice','uploadVoice','downloadVoice','chooseImage','previewImage','uploadImage','downloadImage','getNetworkType','openLocation','getLocation','hideOptionMenu','showOptionMenu','closeWindow','scanQRCode','chooseWXPay','openProductSpecificView','addCard','chooseCard','openCard'] });";//'checkJsApi',
         return(result);
     }
     catch (Exception ex)
     {
         return("var error='" + ex.Message.Replace("\r\n", "").Replace("\n", "").Replace("\t", "").Replace("<br>", "").Replace("'", "\"") + "';");
     }
 }
示例#3
0
        /// <summary>
        /// 获取package带参数的签名包
        /// </summary>
        /// <returns></returns>
        public string GetRequestURL()
        {
            this.CreateMd5Sign();
            var sb    = new StringBuilder();
            var akeys = new ArrayList(Parameters.Keys);

            akeys.Sort();
            foreach (string k in akeys)
            {
                var v = (string)Parameters[k];
                if (null != v && String.Compare("key", k, StringComparison.Ordinal) != 0)
                {
                    sb.Append(k + "=" + PayUtil.UrlEncode(v, GetCharset()) + "&");
                }
            }
            //去掉最后一个&
            if (sb.Length > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }
            return(sb.ToString());
        }