Some use of SMS interface for China Telecom Sky-wing open platform

Source: Internet
Author: User

Description of the section that gets the access token:

Development of sky-Wing SMS Interface Document link: http://open.189.cn/index.php?m=content&c=index&a=lists&catid=62

Actually getting tokens is very simple, which is to assemble the interface address and the required parameters according to the instructions of the SMS interface, then send a POST request and then be able to get to the returned JSON-formatted string.

Based on the SMS interface just above, we choose the simplest way to get tokens, that is, " application two " in the document.

Application two: Under the standard client credentials authorization mode (CC licensing mode) of OAuth 2.0, the application can invoke the interface by its own application ID and application key. Direct access to an at access token without user authorization (User-independent access token, referred to as Uiat).

Unlike a normal at token, the Uiat token can only be used to invoke an open API interface that does not require user authorization, such as a music list, while a normal at token can be used to invoke an open API interface that requires user authorization and to invoke an open interface that does not require user authorization. Uiat tokens are used in collaborative applications where user logons are not required, although their use is relatively limited in scope than ordinary at tokens, but the data form is basically consistent.

Call Address:Https://oauth.api.189.cn/emp/oauth2/v3/access_token

Request Method: Post

Hosting protocol: HTTPS

Parameters:

The following code can obtain tokens normally:

1  Packagecom.wyl.sms;2 3 Importjava.io.IOException;4 5 Importcom.wyl.http.UtilHttp;6 7  Public classutilsms {8     Private StaticString app_id = "Your own AppID";9     Private StaticString App_secret = "Your own SECRET";Ten     //gets the interface address of the access token, as described inhttp://open.189.cn/index.php?m=content&c=index&a=lists&catid=62 Interface Documentation One     Private StaticString Url_get_token = "Https://oauth.api.189.cn/emp/oauth2/v3/access_token"; A      -      -     /** the * Assembly Parameters - * See:http://open.189.cn/index.php?m=content&c=index&a=lists&catid=62 -      * @paramRefresh_token -      * @paramapp_id +      * @paramApp_secret -      * @param State +      * @return A      */ at@SuppressWarnings ("All") -     Private Staticstring Buildpara (String app_id,string app_secret,string state) { -StringBuilder entity =NewStringBuilder (); -Entity.append ("grant_type=" + "Client_credentials"); -Entity.append ("&app_id=" +app_id); -Entity.append ("&app_secret=" +App_secret); inEntity.append ("&state=" +State ); -         returnentity.tostring (); to     } +     /** - * Get access tokens the      * @returnreturns the JSON-formatted token information returned by the telco server *      * @throwsIOException $      */Panax Notoginseng      Public StaticString Getaccesstoken ()throwsioexception{ -String Weburl = url_get_token+ "?" +buildpara (app_id, App_secret, "320"); theString token =utilhttp.sendpostrequest (weburl); +         returntoken; A     } the     /** + * Normal access to tokens -      * @paramargs $      * @throwsIOException $      */ -      Public Static voidMain (string[] args)throwsIOException { -System.out.println ("token:" +Getaccesstoken ()); the     } -}

Utilhttp.java:

1  Packagecom.wyl.http;2 3 ImportJava.io.BufferedReader;4 Importjava.io.IOException;5 ImportJava.io.InputStreamReader;6 Importjava.net.HttpURLConnection;7 ImportJava.net.URL;8 9  Public classUtilhttp {Ten      Publicutilhttp () { One          A     } -     /** - * Send a POST request based on the incoming URL address the      * @paramWeburl -      * @returnreturns the data returned by the request, converted to a string -      * @throwsIOException -      */ +      Public StaticString Sendpostrequest (String weburl)throwsioexception{ -URL url =NewURL (weburl); +HttpURLConnection conn =(HttpURLConnection) url.openconnection (); AConn.setdoinput (true); atConn.setdooutput (true); -Conn.setrequestmethod ("POST"); - Conn.connect (); -BufferedReader reader =NewBufferedReader (NewInputStreamReader (Conn.getinputstream ())); - String Line; -StringBuilder Builder =NewStringBuilder (); in          while(line = Reader.readline ())! =NULL) { - Builder.append (line); to         } +         return(builder.tostring () = =NULL?"": Builder.tostring ()); -     } the}

, the code executes the result:

Some use of SMS interface for China Telecom Sky-wing open platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.