Mobile API Development

Source: Internet
Author: User

Mobile Phone App Interface

Interface: The client sends a request to the server

Interface: 1.URL Address: / http Domain name / Controller /Method or https://

2.test.php processing client sends data

3. Data Return (Json,xml)

Json_encode () converts an array to a string

<xml version= ' 1 ' >

<root>

<username> Zhang San </username>

</root>

Interface: 1. Open Interface

2. Non-Open Interface (ex: public number) need Api_token

users need to register an interface account on the interface platform, the interface platform will give developers a

Households UID and user key secret

Api_token : MD5 (uid+secret+ current time)

http://test.com/ Api_token Expiration Time

http://test.com/return data? Uid=xx & Api_token=xx

User_token user authentication is logged in

Interface Request mode:get post<form></form>

Test Tools   

The client sends the request Content format:

1. Request data format:content-type:application/json

Request data :{'username': Bobo, ' Password ' : 123456}

Server-side:$data = file_get_content ("php://input" )

json_decode ($data, True) parses a Json string into an array

2. Request data format:content-type:application/x-www-form-urlencoded

equivalent to the form form,PHP will automatically parse the fill $_post

Request data:username=bobo&password=123456

server-side fetch data:1.$_post

2.file_get_contents ('php://input')

3. when uploading images via form form on the server side :

content-type:multipart/form-data picture binary stream format

server side:$xrl = file_get_contents ('php://input' )

file_put_contents (' picture . jpg ', $XRL) ; picture stored to server

server-side receive data:

Php://input GET request data from any device

file_get_contents ('php://input')

user_id = " WX " . MD5 (Username.rand ())

User_secret = MD5 (Username.time (). Random number)

RAND () generates random numbers

Using non-public interfaces

1. first to interface platform registration account, interface platform to assign user UID and user key secret

2. generate an API credential based on user ID and user key secret Api_token

Http://xxx.test.com/api/index/create_api_token?uid=xx&secret=xx

Request Method : Get

return value:JSON format succeeded {"status": $,"api_token " : XXX}

failed {"status": 201}

remark: api_token validity

3. when requesting the interface, you need to bring the Api_token

Http://xxx.test.com/api/index/get_goods_list?api_token=xxx

Request method:Get

return Value: Success {"status"=>200} failed

4. client sends data to server side Api_token

Http://xxx.test.com/api/index/add_goods?api_token=xxx

Description: Add product information

data format:JSON {'goods_name': Product name,' Goods_price': Commodity price}

Request method:Post

5. Login successfully generated user credentials User_token

Http://xxx.test.com/api/index/login?Api_token=xxx

Data format: {"username": User name,"password": Password } POST Request

Request succeeded : {"status": 200m,"token " : User credentials, "username": " User Information " }

6. Verifying User Login

Http://xxx.test.com/api/index/getinfo?User_token=xxx&user_id=xxx

data Format : JSON Application/json

Request method:Post

Non-external interface

1. Create a table for the user (developer) of the storage interface Tb_api_user

2.Tb_api_token is used to verify that the developer has permission to use the interface

external Interface (Public interface)

http://www.test.com/or https://

data formats that are returned to the mobile end are in JSON, a cross-platform data format

Json_encode (array) converts an array to a JSON string

Json_decode (JSON string,true) converts a JSON string into an array

User_token user credentials: Used to verify that the user is logged on

User_token = MD5 (Uid.time (). Random number. Web site key (fixed string)//Unique

Mobile API Development

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.