Wo+ Open Platform: API call Development Notes (Phone Billing interface 2.0)

Source: Internet
Author: User

wo+ capacity sharing platform (http://open.wo.com.cn) is an open platform launched by China Unicom, with rich telecommunications capability resources and deep integration of mining third-party capacity resources, etc.,wo+ The API provided by the platform is simple and elegant restful style, which greatly facilitates the use of developers.

The last paragraph is nonsense, and now I'm going to go back to the simple example of how the Wo+ platform API is simple and easy to use.

This code is shown in: Https://github.com/sharetop/WoPlus_Java_SDK


A: Confirmation Process


Take the maximum number of calls "Billing capacity 2.0" as an example, first look at the process.

From the user operation level, the small charge is divided into two steps, the first step, enter the phone number to obtain the verification code, the second step, enter the verification code, confirm payment.



For the wo+ platform, we need two APIs: sending a payment verification code and a pay-per-payment interface.


B: Studying the document


Then we need to read the interface and send a payment verification code with the first API as an example.

According to the description of the document (http://open.wo.com.cn/aep/consumerCapDetail.html?apiPackageId=00000000-0000-0000-0000-500000801000), As can be seen, it is a POST request, HTTP header to declare contenttype and accept, this is very easy. The main thing is that the authorization is a bit different, this is a sign-on field, which needs to fill in a Appkey and Token,appkey is the application logo after the wo+ platform created the app, Tokens, however, need to be obtained based on Appkey and Appsecret (another interface is involved).

The message body, it is simpler, we need to make a map into a JSON string, as Stringentity sent out, OK.

So, the simplest solution we can think of is to use httpclient to encapsulate the invocation logic.

C: Writing code

the scheme determines , the code comes with . See the example project in woplusclient in postjsonentity method.

Static synchronized Woplusresponse postjsonentity (String api_url,hashmap<string,string> auth,hashmap< String,object> params) throws Exception {//Converts the message body parameter into a string, JSON format string body=json.tojsonstring (params, Serializerfeature.writenullnumberaszero);//We use Stringentity to package the request stringentity entity = new Stringentity (Body, "utf-8" ); Closeablehttpclient httpclient = Httpclients.createdefault ();                HttpPost HttpPost = new HttpPost (Api_url); The request for HTTP headers in the corresponding document Httppost.addheader ("Content-type", "Application/json;charset=utf-8"); Httppost.addheader (" Accept "," Application/json "); StringBuilder sb=new StringBuilder (); for (String K:auth.keyset ()) {Sb.append (","). Append (k). Append ("=\"). Append ( Auth.get (k)). Append ("\" ");} try{//Add that Authorization field again Httppost.addheader ("Authorization", sb.tostring (). substring (1)); HttpPost. Setentity (entity); Logger.debug (Entityutils.tostring (entity)); Closeablehttpresponse response = Httpclient.execute (HttpPost); try{httpentity respentity = respOnse.getentity (); if (respentity! = null) {BODY = entityutils.tostring (respentity); Logger.debug (body);}} finally {response.close ();}} Finally{httpclient.close ();} Return _transobject (Json.parseobject (body));}

Three parameters, the first is the requested URL, that is, the request URI in the document, the second is the two fields in the authorization string, Appkey and token, the third is the requested message body, also in the map package.

Appkey and tokens need to be assembled into a string as the value of the authorization;

The message body is encapsulated in map and can be easily exported to a string type with the help of the JSON tool.

Isn't it simple?


As for the second API, extrapolate can!


Wo+ Open Platform: API call Development Notes (Phone Billing interface 2.0)

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.