Exemplo n.º 1
0
        /// <summary>
        /// 注册支付脚本
        /// <param name="weixinId"></param>
        /// <param name="errorMessage"></param>
        /// </summary>
        public bool RegisterJWeiXin(int weixinId, out string errorMessage)
        {
            try
            {
                errorMessage = string.Empty;
                var ticket = WeiXinCRMComm.getJsApiTicket(weixinId, out errorMessage);
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    return(false);
                }

                var wxModel = new BLL.wx_userweixin().GetModel(weixinId);
                if (wxModel == null)
                {
                    errorMessage = "不合法的参数wid";
                    return(false);
                }

                appId     = wxModel.AppId;
                nonceStr  = JSSDKHelper.GetNoncestr();
                timestamp = JSSDKHelper.GetTimestamp();
                signature = new JSSDKHelper().GetSignature(ticket, nonceStr, timestamp, Request.Url.ToString());

                IsRegister = 1;
                return(true);
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
                return(false);
            }
        }
Exemplo n.º 2
0
        public void WeChatConfigInit(int wid, string url)
        {
            try
            {
                string errorString;
                var    ticket = WeiXinCRMComm.getJsApiTicket(wid, out errorString);
                if (!string.IsNullOrEmpty(errorString))
                {
                    HttpContext.Current.Response.Write(AjaxResult.Error(errorString));
                }
                else
                {
                    var wxModel = new BLL.wx_userweixin().GetModel(wid);
                    if (wxModel == null)
                    {
                        HttpContext.Current.Response.Write(AjaxResult.Error("不合法的参数wid"));
                        return;
                    }

                    var noncestr  = JSSDKHelper.GetNoncestr();
                    var timestamp = JSSDKHelper.GetTimestamp();
                    var singature = new JSSDKHelper().GetSignature(ticket, noncestr, timestamp, url);

                    var result = new
                    {
                        appId     = wxModel.AppId,
                        timestamp = timestamp,
                        nonceStr  = noncestr,
                        signature = singature
                    };

                    HttpContext.Current.Response.Write(AjaxResult.Success(result));
                }
            }
            catch (Exception exception)
            {
                HttpContext.Current.Response.Write(AjaxResult.Error(exception.Message));
            }
        }