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 = "数据获取成功" })); }
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()); }