在我们做营销活动或推广宣传的时候,容易遇到域名被封,无法在微信内打开常用下载软件,APP等。这时需要微信跳转外部浏览器打开页面的功能,对于微信默认可以通过:点击右上角的三点,点击“在浏览器中打开”。但是对于很多用户而言并不知道这样的实现,所以需要在代码中进行相关操作。直接判断微信的ua,如果是在微信内置浏览器中打开,弹出一个遮罩提示用户在浏览器中打开下载,并且不加关闭的按钮。这样子用户就只能在浏览器中打开,并且可以直接下载应用了
1.微信跳转链接是什么意思呢 ? 微信跳转链接是能实现微信内打开链接直接自动跳转到浏览器访问 , 使用的是第三方微信接口。
2.什么时候需要用到微信跳转链接 ? 当你的微信推广链接在微信被拦 , 导致用户无法下载 APP 或者无法正常访问指定页面的情况下 , 担心会被拦截提前想预防的情况下。
3.微信跳转链接是否会被拦截?微信跳转链接通常不会被微信拦截,因为本就是使用的微信 scheme 接口
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();
}
}