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. Has a wealth of telecommunications capabilities and deep integration of the mining of third-party capabilities, and other resources. the API provided by the wo+ platform is a simple and elegant restful style that greatly facilitates the use of developers.

The upper paragraph is nonsense. Now we have to. I'll use a simple demo sample to illustrate how simple and useful the API of the wo+ platform is.

Please refer to this code: Https://github.com/sharetop/WoPlus_Java_SDK


A: Confirmation Process


Take the "Billing Capacity 2.0" of the largest number of calls as an example. Take a look at the process first.

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.



corresponding wo+ platform. We need two APIs: send a payment verification code and a pay-per-payment interface.


B: Studying the document


Then, we need to study the interface. Take the first API as an example. Send a payment verification code.

According to the descriptive description of the document (http://open.wo.com.cn/aep/consumerCapDetail.html?apiPackageId=00000000-0000-0000-0000-500000801000). Can see that it is a POST request, HTTP header to declare contenttype and accept. This is very easy. The main is that authorization a bit different, this is a right to sign the field, which needs to fill in a Appkey and Token,appkey is the wo+ platform to create an application after the application logo, Tokens need to be based on Appkey and Appsecret (involving an interface).

The message body. It's even easier. We need to make a map into a JSON string and send it as a stringentity, OK.

So. The simplest solution we've ever thought of IS. Use HttpClient to encapsulate the invocation logic.

C: Writing code

The plan is OK, and the code comes . See the postjsonentity method in Woplusclient in the Demo sample project .

Static synchronized Woplusresponse postjsonentity (String api_url,hashmap<string,string> auth,hashmap< String,object> params) throws Exception {//Converts the body of the message 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 is 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 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 of the parameters. The first one is the URL of the request. That is, the request URI in the document, and the second is the two fields in the authorization string. Appkey and tokens. The third one is the message body of the request. Same in 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 output as a string type with the help of the JSON tool.

Isn't it very easy?


As for the second API. Extrapolate can do it!


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.