1, an overview of the

Short url is numerous, the benefits of easy to remember, occupy less characters and so on, many will be appeared on the market now long url into a short url, but because they are a small company operating behind the scenes, so it is unlikely, in the face of close service may at any time, it also cause we will convert the short url will failure of chain! So how to make the converted short url permanent?

2. Convert long links to short links by using the wechat public account interface

The original link used by developers to generate two-dimensional code (commodity, payment TWO-DIMENSIONAL code, etc.) is too long, resulting in a decrease in the speed and success rate of scanning code. Converting the original long link through this interface into a short link to regenerate two-dimensional code will greatly improve the speed and success rate of scanning code. Wechat public account platform provides long link to short link interface:

The HTTP request method: POST at https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKENCopy the code

Parameters that

parameter Whether must instructions
access_token is Call interface credentials
action is Fill in long2short here, which means the long link turns to the short link
long_url is Long links to be converted can be urls in the format of http://, https://, or weixin://wxpay

Call for

curl -d "{\"action\":\"long2short\",\"long_url\":\"http://wap.koudaitong.com/v2/showcase/goods?alias=128wi9shh&spm=h56083&redire ct_count=1\"}" "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN"Copy the code

Under normal circumstances, wechat will return the following JSON data packets to the public number:

{"errcode":0,"errmsg":"ok","short_url":"http:\/\/w.url.cn\/s\/AvCo6Ih"}
Copy the code

Reference code

/ / / < summary > / / / / / short/long link link < summary > / / / < param name = "longUrl" > long links < param > / / / < returns > < / returns > [HttpPost] [ValidateInput(false)] [LoginAuthorize] public ActionResult GetShortUrl(string longUrl) { WeixinOfficialAccountEntity currentWeixinOfficialAccountEntity = RDIFrameworkService.Instance.WeixinBasicService.GetCurrentOfficialAccountEntity(ManageProvider.Provider.Current()); string token = currentWeixinOfficialAccountEntity.AccessToken; / / WeChat request address string url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=" + token; / / request json string data = "{\" action \ ": \" long2short \ ", \ "long_url \" : \ "" + longUrl +" \ "} "; string ret = string.Empty; try { byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(data); // Convert HttpWebRequest webReq = (HttpWebRequest) webrequest.create (new Uri(url)); webReq.Method = "POST"; webReq.ContentType = "application/json"; webReq.ContentLength = byteArray.Length; Stream newStream = webReq.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length); // Write the argument newstream.close (); HttpWebResponse response = (HttpWebResponse)webReq.GetResponse(); var ce = response.ContentEncoding; StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8")); ret = sr.ReadToEnd(); sr.Close(); response.Close(); newStream.Close(); } catch (Exception ex) {} // under normal circumstances, wechat will return the following JSON packets to the public id:  //{"errcode":0,"errmsg":"ok","short_url":"http:\/\/w.url.cn\/s\/AvCo6Ih"} string errcode = ""; // Error code. string errmsg = ""; // Error message. string short_url = ""; // Short link. // Parse the response message if (! string.IsNullOrWhiteSpace(ret)) { JObject jo = (JObject)JsonConvert.DeserializeObject(ret); errcode = jo["errcode"].ToString(); // Error code. errmsg = jo["errmsg"].ToString(); // Error message. short_url = jo["short_url"].ToString(); // Short link. } return Content(new JsonMessage { Success = true, Data = short_url, Type = ResultType.Success, Message = errmsg }.ToString()); }Copy the code

##3, use effect reference ##


Above the interface we link address to blog.rdiframework.net/article/190 through we provide long links with short link interface functions into the short link w.u rl. Cn/s/ALO1xZC.

Refer to the article

Wechat public platform technical document – official

Senparc.Weixin SDK + official website example source code

RDIFramework.NET – Based. NET rapid information system development framework – series directory

RDIFramework.NET ━.NET Rapid information system development framework ━ Workflow components

RDIFramework.NET SOA solution (distributed as Windows services, WinForm and IIS) – distributed applications

RDIFramework.NET code generator new V3.5 release – major upgrade


Over the years, thanks to supporters and users of the RDIFramework.NET framework, you can find out more at the following address.

RDIFramework.NET official website: www.rdiframework.net/

RDIFramework.NET official blog: blog.rdiframework.net/

At the same time need to explain, all technical articles in the future to the official website prevail, welcome everyone to collect!

RDIFramework.NET framework has been developed by a professional team for a long time, and is always updated and upgraded. Please feel free to use it!

Please follow the official wechat account of RDIFramework.net (wechat id: Guosisoft) to keep abreast of the latest developments.

Scan the QR code for immediate attention