public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; //数据验证 //获取微信配置信息 string url = context.Request.QueryString["url"]; string shareurl = context.Request.QueryString["shareurl"]; JSSDK sdk = new JSSDK("wxf89835502774e9c2", "385fa8177eabd63abd74236ef9b1f684", "", false); var qianming = HttpUtility.UrlDecode(url, System.Text.Encoding.GetEncoding(65001)); shareinfo share = new shareinfo(); int id = int.Parse(weitang.StringExtensions.GetNumber(url.Substring(url.LastIndexOf('/') + 1)).ToString()); WechatEntities dc = new WechatEntities(); var v = dc.ShareInfo.Where(a => a.Id == id).FirstOrDefault(); share.url = v.ShareURL; share.title = v.Title; share.describtion = v.Description; share.imags = "http://www.bbpdt.cn/" + v.Image; SignPackage config = sdk.GetSignPackage(qianming, JsApiEnum.chooseWXPay | JsApiEnum.onMenuShareTimeline | JsApiEnum.onMenuShareAppMessage | JsApiEnum.onMenuShareQQ | JsApiEnum.onMenuShareWeibo); // return new ApiResponse { r = "1", d = new { config = config }, m = "数据获取成功" }; context.Response.Write(JsonConvert.SerializeObject(new ApiResponse { r = "1", d = new { config = config, share = share }, m = "数据获取成功" })); }
/// <summary> /// 获取jssdk签名配置对象 /// </summary> /// <param name="url">当前页面url</param> /// <param name="jsapi">JsApiEnum,如:JsApiEnum.scanQRCode|JsApiEnum.onMenuShareQQ</param> /// <returns>微信公众平台JsSdk的配置对象</returns> public SignPackage GetSignPackage(string url, JsApiEnum jsapi) { /* * 签名字段 * noncestr=Wm3WZYTPz0wzccnW * jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg * timestamp=1414587457 * url=http://mp.weixin.qq.com?params=value */ string noncestr = this.CreateNonceStr(16); string jsapi_tkcket = this.GetJsApiTicket(); long timestamp = TimeStamp.Now(); Dictionary <string, string> signData = new Dictionary <string, string>() { { "noncestr", noncestr }, { "jsapi_ticket", jsapi_tkcket }, { "timestamp", timestamp.ToString() }, { "url", url } }; SignPackage result = new SignPackage() { AppId = this.appId, Timestamp = timestamp, NonceStr = noncestr, Debug = this._debug, Signature = new Signature().Sign(signData), Url = url, JsApiList = jsapi.ToString().Replace(" ", "").Split(',') }; return(result); }
/// <summary> /// 获取签名包 /// </summary> /// <param name="url"></param> /// <returns></returns> public static SignPackage FetchSignPackage(String url) { JSTicket jsticket = FetchJSTicket(); SignPackage signPackage = FetchSignPackage(url, jsticket); return(signPackage); }
/// <summary> /// 获取签名包 /// </summary> /// <param name="url"></param> /// <returns></returns> public static SignPackage FetchSignPackage(String url, JSTicket jsticket) { string timestamp = SignPackageHelper.ConvertToUnixTimeStamp(DateTime.Now); string nonceStr = SignPackageHelper.CreateNonceStr(); if (jsticket == null) { return(null); } // 这里参数的顺序要按照 key 值 ASCII 码升序排序 string rawstring = Keys.jsapi_ticket + "=" + jsticket.ticket; rawstring += "&" + Keys.noncestr + "=" + nonceStr; rawstring += "&" + Keys.timestamp + "=" + timestamp; rawstring += "&" + Keys.url + "=" + url; string signature = SignPackageHelper.Sha1Hex(rawstring).ToLower(); var signPackage = new SignPackage() { agentId = BP.Sys.SystemConfig.Ding_AgentID, corpId = BP.Sys.SystemConfig.Ding_CorpID, timeStamp = timestamp, nonceStr = nonceStr, signature = signature, url = url, rawstring = rawstring, jsticket = jsticket.ticket }; return(signPackage); }
public ActionResult JsApi() { SignPackage sSignConfig = JSSDKHelper.GetQySignPackage(QyJsApiEnum.getNetworkType); System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); ViewBag.config = serializer.Serialize(sSignConfig); return(View()); }
/// <summary> /// 首页 /// </summary> /// <returns></returns> public ActionResult Jwplayer() { WxHelper wxhelper = new WxHelper(); SignPackage config = wxhelper.GetSignPackage(JsApiEnum.onMenuShareAppMessage | JsApiEnum.onMenuShareTimeline, false); JavaScriptSerializer serializer = new JavaScriptSerializer(); ViewBag.config = serializer.Serialize(config); return(View()); }
public ResponseModel <SignPackage> GetConfig(string Url = "") { JSSDK sdk = new JSSDK(appId, secret, false); SignPackage config = sdk.GetSignPackage(JsApiEnum.scanQRCode | JsApiEnum.onMenuShareQQ | JsApiEnum.onMenuShareTimeline | JsApiEnum.onMenuShareAppMessage, Url); var result = new ResponseModel <SignPackage>(); result.error_code = Models.Result.SUCCESS; result.total_count = 1; result.data = config; return(result); }
public ActionResult Index() { JSSDK sdk = new JSSDK(WechatParamList.APP_ID, WechatParamList.APP_SECRET, true); JsApiEnum jsApilist = (JsApiEnum)0x3ffffffff; SignPackage config = sdk.GetSignPackage(jsApilist); JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); ViewBag.config = serializer.Serialize(config); return(View()); }
// public SignPackage config; public string GetWchatConfig() { string appId = System.Configuration.ConfigurationManager.AppSettings["WeChatAppId"]; string appSecret = System.Configuration.ConfigurationManager.AppSettings["WeChatAppSecret"]; bool debug = System.Configuration.ConfigurationManager.AppSettings["WeChatJsDebug"].ToLower() == "true"; JSSDK sdk = new JSSDK(appId, appSecret, debug); SignPackage config = sdk.GetSignPackage(JsApiEnum.onMenuShareAppMessage | JsApiEnum.scanQRCode | JsApiEnum.onMenuShareQQ | JsApiEnum.onMenuShareTimeline); System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); config.jsApiList = new string[] { "checkJsApi", "onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo", "onMenuShareQZone", "hideMenuItems", "showMenuItems", "hideAllNonBaseMenuItem", "showAllNonBaseMenuItem", "translateVoice", "startRecord", "stopRecord", "onVoiceRecordEnd", "playVoice", "onVoicePlayEnd", "pauseVoice", "stopVoice", "uploadVoice", "downloadVoice", "chooseImage", "previewImage", "uploadImage", "downloadImage", "getNetworkType", "openLocation", "getLocation", "hideOptionMenu", "showOptionMenu", "closeWindow", "scanQRCode", "chooseWXPay", "openProductSpecificView", "addCard", "chooseCard", "openCard" }; return(serializer.Serialize(config)); }
// // GET: /index/ public ActionResult index() { /* * wx.config({ * debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 * appId: '', // 必填,公众号的唯一标识 * timestamp: , // 必填,生成签名的时间戳 * nonceStr: '', // 必填,生成签名的随机串 * signature: '',// 必填,签名,见附录1 * jsApiList: [] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 * }); */ /* web.config 设置appid,appsecret,dubug * <appSettings> * <add key="WeChatAppId" value="your appid here"/> * <add key="WeChatAppSecret" value="your appsecret here"/> * <add key="WeChatJsDebug" value="true"/> * </appSettings> */ string appId = System.Configuration.ConfigurationManager.AppSettings["WeChatAppId"]; string appSecret = System.Configuration.ConfigurationManager.AppSettings["WeChatAppSecret"]; bool debug = System.Configuration.ConfigurationManager.AppSettings["WeChatJsDebug"].ToLower() == "true"; JSSDK sdk = new JSSDK(appId, appSecret, debug); //JsApiEnum使用方法 //JsApiEnum jsApilist = JsApiEnum.onMenuShareQQ | JsApiEnum.chooseImage; //0x3ffffffff 是使用全部接口 JsApiEnum jsApilist = (JsApiEnum)0x3ffffffff; SignPackage config = sdk.GetSignPackage(jsApilist); System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); ViewBag.config = serializer.Serialize(config); //string str_config = "{"; //str_config += string.Format("debug:{0},", config.debug ? "true" : "false"); //str_config += string.Format("appId:'{0}',", config.appId); //str_config += string.Format("timestamp:{0},", config.timestamp); //str_config += string.Format("nonceStr:'{0}',", config.nonceStr); //str_config += string.Format("signature:'{0}',", config.signature); //str_config += "jsApiList:["; //for (int i = 0; i < config.jsApiList.Length; i++) //{ // if (i > 0) // str_config += ","; // str_config += string.Format("'{0}'", config.jsApiList[i]); //} //str_config += "]}"; //ViewBag.config = str_config; return(View()); }
/// <summary> /// 获取企业wx.config结构 /// </summary> /// <param name="jsapi">jsapi组合(例如:JsApiEnum.scanQRCode|JsApiEnum.onMenuShareQQ)</param> /// <returns></returns> public static SignPackage GetQySignPackage(QyJsApiEnum jsapi) { string sAppid = XmlToEntity.GetQYConfig().CorpID; string sJsapi_ticket = GetJsApiTicket(WxPlatFormTypeEnum.QY, "qy_jsapi_tikect"); HttpContext httpcontext = System.Web.HttpContext.Current; string sUrl = httpcontext.Request.Url.AbsoluteUri; string sNonce = GetNonceStr(); string sTimesTamp = GetTimesTamp(); string sSignature = GetSignature(sJsapi_ticket, sNonce, sTimesTamp, sUrl); SignPackage sp = new SignPackage() { debug = "true", appId = sAppid, timestamp = sTimesTamp, nonceStr = sNonce, signature = sSignature, jsApiList = jsapi.ToString().Replace(" ", "").Split(',') }; return(sp); }
/// <summary> /// APP用户登录 /// </summary> /// <param name="LoginName"></param> /// <param name="pass_word"></param> /// <param name="ip"></param> /// <param name="signPackage"></param> /// <returns></returns> public User Login(string LoginName, string pass_word, string ip, SignPackage signPackage) { using (ISession s = SessionFactory.Instance.CreateSession()) { //当前用户是否存在 User user = s.Get <User>("where login_name = @0", LoginName); if (user == null) { user = s.Get <User>("where mobile = @0", LoginName); } //如果用户为空 if (user == null) { user = new User(); user.login_code = StateCode.State_4; return(user); } //用户已被冻结 if (user.state == 0) { user = new User(); user.login_code = StateCode.State_209; return(user); } //如果用户用户密码都正确 if (user != null && !user.psw.ToUpper().Equals(StringHelper.ConvertTo32BitSHA1(pass_word).ToUpper())) { user.login_code = StateCode.State_4; return(user); } //登录成功 user.login_code = StateCode.State_200; //获取用户图像 Img img = s.Get <Img>("where biz_type = @0 and biz_id = @1", ImgType.User, user.id); if (img != null) { user.head_img = img.getImgUrl(); } //登录是否成功 s.ExcuteUpdate("update tb_user set last_ip = login_ip,login_ip = @0,last_time = login_time,login_time = @1,login_count = login_count + 1 where id = @2", ip, DateTime.Now, user.id); //重置当前用户所有令牌状态 //s.ExcuteUpdate("update tb_user_token set is_enable = @0 where user_id = @1", false, user.id); signPackage.Token = Guid.NewGuid().ToString("N"); UserToken token = new UserToken(); token.last_time = DateTime.Now; token.created_date = DateTime.Now; token.os = signPackage.OS; token.user_id = user.id; token.imei = signPackage.IMEI; token.imsi = signPackage.IMSI; token.token = signPackage.Token; token.is_enable = true; //s.Insert(token); return(user); } }
/// <summary> /// 注册 /// </summary> /// <param name="user"></param> /// <param name="rpsw"></param> /// <param name="vcode"></param> /// <returns></returns> public StateCode Register(User user, string rpsw, string vcode, SignPackage signPackage) { using (ISession s = SessionFactory.Instance.CreateSession()) { try { s.StartTransaction(); //短信验证码不存在 SmsMessage sms = s.Get <SmsMessage>("where mobile = @0 and type = @1", user.mobile, 1); if (sms == null) { return(StateCode.State_54); } //验证码错误 if (!vcode.Equals(sms.content)) { return(StateCode.State_53); } //计算时间间隔 TimeSpan t = DateTime.Now - sms.created_time; if (t.TotalSeconds > 300) { return(StateCode.State_52); } //是否已经被注册 int exist_m = s.Exist <User>("where mobile = @0", user.mobile); if (exist_m > 0) { return(StateCode.State_202); } //两次密码不一致 if (!rpsw.Equals(user.psw)) { return(StateCode.State_203); } user.state = 1; user.login_name = user.mobile; user.created_date = DateTime.Now; user.psw = StringHelper.ConvertTo32BitSHA1(user.psw); s.Insert(user); //用户详情 UserDetail detail = new UserDetail(); detail.user_id = user.id; s.Insert(detail); if (signPackage != null) { //重置当前用户所有令牌状态 s.ExcuteUpdate("update tb_user_token set is_enable = @0 where user_id = @1", false, user.id); signPackage.Token = Guid.NewGuid().ToString("N"); UserToken token = new UserToken(); token.created_date = DateTime.Now; token.os = signPackage.OS; token.last_time = DateTime.Now; token.user_id = user.id; token.imei = signPackage.IMEI; token.imsi = signPackage.IMSI; token.token = signPackage.Token; token.is_enable = true; s.Insert(token); } s.Commit(); return(StateCode.State_200); } catch (Exception ex) { s.RollBack(); APILogs log = new APILogs(); log.content = "[Register]注册异常==》" + ex.ToString(); log.created_date = DateTime.Now; s.Insert(log); return(StateCode.State_500); } } }