WeChat jump to external browser code

When we are doing marketing activities or promotion, it is easy to encounter domain names being blocked, and it is impossible to open commonly used downloading software, APP, etc. in WeChat. At this time, the function of WeChat to jump to the external browser to open the page is required. For WeChat, it can be passed by default: Click the three dots in the upper right corner, and click "Open in browser". But for many users, they don't know such an implementation, so they need to perform related operations in the code. Directly judge the ua of WeChat. If it is opened in the WeChat built-in browser, a mask will pop up to prompt the user to open the download in the browser without adding a close button. In this way, the sub-user can only open it in the browser, and can directly download the application
1. What does the WeChat jump link mean? The WeChat jump link can realize that the link opened in WeChat automatically jumps to the browser to visit, use It is a third-party WeChat interface.
2. When do you need to use the WeChat jump link? When your WeChat promotion link is blocked on WeChat, causing users to be unable to download the APP or access the specified page normally, you are worried about being blocked and you want to prevent it in advance.
3. Will WeChat redirect links be blocked? WeChat redirect links are usually not intercepted by WeChat, because the WeChat scheme interface is used.
WeChat jump to external browser code


namespace ConsoleAPI{
    class Program{
        static void Main(string[] args){
            string url = "http://api.monkeyapi.com";

            var parameters = new Dictionary<string, string>();

            parameters.Add("appkey" , "appkey"); //您申请的APPKEY
            parameters.Add("url" , "www.monkeyapi.com"); //需要查询的网站

            string result = sendPost(url, parameters, "post");

            // 代码中JsonObject类下载地址:http://download.csdn.net/download/gcm3206021155665/7458439
            JsonObject newObj = new JsonObject(result);
            String errorCode = newObj["error_code"].Value;

            if (errorCode == "0")
            {
                Debug.WriteLine("成功");
                Debug.WriteLine(newObj);
            }
            else
            {
                //Debug.WriteLine("请求异常");
                Debug.WriteLine(newObj["error_code"].Value+":"+newObj["reason"].Value);
            }
        }

        /// <summary>
        /// Http (GET/POST)
        /// </summary>
        /// <param name="url">请求URL</param>
        /// <param name="parameters">请求参数</param>
        /// <param name="method">请求方法</param>
        /// <returns>响应内容</returns>
        static string sendPost(string url, IDictionary<string, string> parameters, string method){
            if (method.ToLower() == "post")
                {
                    HttpWebRequest req = null;
                    HttpWebResponse rsp = null;
                    System.IO.Stream reqStream = null;
                try
                {
                    req = (HttpWebRequest)WebRequest.Create(url);
                    req.Method = method;
                    req.KeepAlive = false;
                    req.ProtocolVersion = HttpVersion.Version10;
                    req.Timeout = 60000;
                    req.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
                    byte[] postData = Encoding.UTF8.GetBytes(BuildQuery(parameters, "utf8"));
                    reqStream = req.GetRequestStream();
                    reqStream.Write(postData, 0, postData.Length);
                    rsp = (HttpWebResponse)req.GetResponse();
                    Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet);
                    return GetResponseAsString(rsp, encoding);
                }
                    catch (Exception ex)
                {
                    return ex.Message;
                }
                finally
                {
                    if (reqStream != null) reqStream.Close();
                    if (rsp != null) rsp.Close();
                }
            }

Guess you like

Origin blog.51cto.com/14933171/2545570