CmsWeb/wx/msg.aspx.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Text;
using Cms.Common;
public partial class wx_msg : System.Web.UI.Page
{
    public static string xtopenid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Cms.BLL.wx_info info = new Cms.BLL.wx_info();
            string appid = info.GetModel(1).AppId;
            string appsecret = info.GetModel(1).AppSecret;
            string url = Request.Url.Host.ToString();
            string redirectUrl = "http://" + url + "/wx/msg.aspx";
         
            if (Request.QueryString["code"] != null && Request.QueryString["code"] != "")
            {
              
                string Code = Request.QueryString["code"].ToString();
                string Str = GetJson("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + appsecret + "&code=" + Code + "&grant_type=authorization_code");
                //微信回传的数据为Json格式,将Json格式转化成对象  
                OAuth_Token Model =wxuser.JSONToObject<OAuth_Token>(Str);
              
                xtopenid = Model._openid;
                openid.Value = Model._openid;
            }
            else
            {
                string posturl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + redirectUrl + "&response_type=code&scope=snsapi_base&state=123#wechat_redirect ";
                Response.Redirect(posturl);
            }

           
        }
    }

    /// <summary>
    /// 接受信息
    /// </summary>
    /// <param name="url">目标连接地址</param>
    /// <returns></returns>
    protected string GetJson(string url)
    {
        WebClient wc = new WebClient();
        wc.Credentials = CredentialCache.DefaultCredentials;
        wc.Encoding = Encoding.UTF8;
        string returnText = wc.DownloadString(url);
        if (returnText.Contains("errcode"))
        {
            //可能发生错误  
后面还有 49 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。