public static Clientresponse Sendclientrequest (list<basicnamevaluepair> params)
{
Clientresponse clientresponse = new Clientresponse ();
list<clientresponsedata> clientresponsedatalist = new arraylist<> ();
Clientresponse.setclientresponsedatalist (clientresponsedatalist);
String url = switch.url + "Returnclientinfo";
HttpClient HttpClient = new Defaulthttpclient ();
Httpclient.getparams (). Setparameter (coreconnectionpnames.connection_timeout,5000);
Httpclient.getparams (). Setparameter (coreconnectionpnames.so_timeout,5000);
HttpPost HttpPost = new HttpPost (URL);
try{
LOG.I ("66666666666666666666", "66666666666666666666");
Httppost.setentity (New urlencodedformentity (params, HTTP. Utf_8));
HttpResponse HttpResponse = Httpclient.execute (HttpPost);
if (Httpresponse.getstatusline (). Getstatuscode () = = 200)
{
StringBuilder builder = new StringBuilder ();
BufferedReader BufferedReader = new BufferedReader (New InputStreamReader (Httpresponse.getentity (). GetContent ()));
for (String s = bufferedreader.readline (); s! = null; s = bufferedreader.readline ())
{
Builder.append (s);
}
LOG.I ("Builder", builder.tostring ());
Jsonobject Jsonobjectboss = new Jsonobject (builder.tostring ());
String jsonobjectstatus = jsonobjectboss.getstring ("status");
String jsonobjectmsg = jsonobjectboss.getstring ("msg");
if (Jsonobjectstatus.equals ("Success")) {
Jsonarray Jsonarray = Jsonobjectboss.getjsonarray ("content");
for (int i = 0; i < jsonarray.length (); i++) {
Jsonobject Jsonobject = (jsonobject) jsonarray.get (i);
Clientresponsedata clientresponsedata = new Clientresponsedata ();
CLIENTRESPONSEDATA.SETCLIENT_ID (jsonobject.getstring ("client_id"));
Clientresponsedata.setclient_name (jsonobject.getstring ("Client_name"));
Clientresponsedata.setclient_phone (jsonobject.getstring ("Client_phone"));
Clientresponsedata.setclient_picture (jsonobject.getstring ("client_picture"));
Clientresponsedata.setclient_address (jsonobject.getstring ("client_address"));
CLIENTRESPONSEDATA.SETUSER_ID (jsonobject.getstring ("user_id"));
Clientresponse.getclientresponsedatalist (). Add (Clientresponsedata);
}
}
Clientresponse.setstatus (Jsonobjectstatus);
Clientresponse.setmsg (JSONOBJECTMSG);
}
Else
{
Clientresponse.setstatus ("error_msg");
Clientresponse.setmsg ("Return error code");
}
}catch (Exception e)
{
E.printstacktrace ();
Clientresponse.setstatus ("Request_error");
CLIENTRESPONSE.SETMSG ("request Error");
}
return clientresponse;
}
This is the Clientresponse class:
public class Clientresponse extends Response
{
List<clientresponsedata> clientresponsedatalist;
Public list<clientresponsedata> getclientresponsedatalist () {
return clientresponsedatalist;
}
public void Setclientresponsedatalist (list<clientresponsedata> clientresponsedatalist) {
This.clientresponsedatalist = clientresponsedatalist;
}
}
This is the Clientresponsedata class:
public class Clientresponsedata implements Serializable
{
Private String client_id;
Private String client_name;
Private String Client_phone;
Private String client_address;
Private String client_picture;
Private String user_id;
Public String getclient_id () {
return client_id;
}
Public String Getclient_name () {
return client_name;
}
public void Setclient_name (String client_name) {
This.client_name = Client_name;
}
Public String getuser_id () {
return user_id;
}
public void setuser_id (String user_id) {
this.user_id = user_id;
}
Public String getclient_picture () {
return client_picture;
}
public void Setclient_picture (String client_picture) {
This.client_picture = client_picture;
}
Public String getclient_address () {
return client_address;
}
public void setclient_address (String client_address) {
this.client_address = client_address;
}
Public String Getclient_phone () {
return client_phone;
}
public void Setclient_phone (String client_phone) {
This.client_phone = Client_phone;
}
public void setclient_id (String client_id) {
this.client_id = client_id;
}
}
This is the switch class:
public class Switch {
public static String URL =http://115.29.40.90/goodsmanager/index.php/home/index/;
}
Next is the data that the client will send to the server:
1, return to the warehouse all items information, without transmitting parameters
Http://115.29.40.90/GoodsManager/index.php/Home/Index/ReturnStoreInfo
Information returned to the client after the server is received:
Return data after failure:
' Status ' = ' ERROR ',
' msg ' = ' query error or no query result ',
' content ' = ' null '
Return data after success:
' Status ' = ' success ',
' msg ' = ' query succeeded ',
' Content ' and $data //This is the returned product contents
2. Add items to the warehouse
Http://115.29.40.90/GoodsManager/index.php/Home/Index/IntoStorage
Data that the client needs to transfer:
GOODS_ID: Item ID, shaped like: ' 00001 '
Goods_num: Number of items, shaped like: ' 2000 '
Goods_name: Name of item: ' Computer '
Goods_vender: Manufacturer, form: ' Asus Computer City '
Goods_type: Model, shaped like: ' Xl520 '
Goods_norms: Item specifications, shaped like: ' Qualified '
Storageunitname: Name of production unit, such as: ' Guangzhou computer City '
Operator: The name of the delivery or delivery person, such as: ' Xiao Ming '
In_out: Outbound or Inbound: 1 represents out of the library, 0 represents the storage, this is an int
Day: Out of the library or the date of storage, such as: ' 1st '
Month: Out of the library or warehousing months, the shape of: ' May '
Year: Out of the library or warehousing period, the shape of: ' 2016 '
' Status ' = ' success ',
' msg ' = ' Insert Success ',
' content ' = ' null '
Insert Error:
' Status ' = ' ERROR ',
' msg ' = ' Insert error ',
' content ' = ' null '
Network errors and other reasons:
' Status ' = ' ERROR ',
' msg ' = ' query error ',
' content ' = ' null '
The product already exists and cannot be inserted repeatedly:
' Status ' = ' exist ',
' msg ' = ' product already exists ',
' content ' = ' null '
3. Delete items
Http://115.29.40.90/GoodsManager/index.php/Home/Index/DeleteStorage
Data that the client needs to transfer:
GOODS_ID: Item ID
The product does not exist:
' Status ' = ' noexist ',
' msg ' = ' user does not exist ',
' content ' = ' null '
Failure due to network and other reasons:
' Status ' = ' ERROR ',
' msg ' = ' query error ',
' content ' = ' null '
Delete succeeded:
' Status ' = ' success ',
' msg ' = ' Delete succeeded ',
' content ' = ' null '
4. Return to inbound or outbound item information by date
Http://115.29.40.90/GoodsManager/index.php/Home/Index/ReadByDay
Data that the client needs to transfer:
Day: Date
Return success:
' Status ' = ' success ',
' msg ' = ' return to Success ',
' Content ' = $end, //This is the return of the product contents
' num ' = $data //This is the number of items returned
The warehouse is not logged:
' Status ' = ' None ',
' msg ' = ' = ' return null ',
' content ' = ' null ',
' num ' = $data
Request error (due to network reason, etc.):
' Status ' = ' ERROR ',
' msg ' = ' request error ',
' content ' = ' null ',
' num ' = ' 0 '
5, monthly return to the storage or inventory information
Http://115.29.40.90/GoodsManager/index.php/Home/Index/ReadByMonth
Data that the client needs to transfer:
Month: Period
6, the year-to-date return to the warehouse or the goods information
Http://115.29.40.90/GoodsManager/index.php/Home/Index/ReadByYear
Data that the client needs to transfer:
Year: Term
5 and 6 of the service side return value is the same as 4;
The format for Android calls is:
list<basicnamevaluepair> pairs = null;
Clientresponse clientresponse = null;
pairs = new arraylist<> ();
Pairs.add (New Basicnamevaluepair ("user_id", "1881555100"));
Clientresponse = fuckyapi.sendclientrequest (pairs);
This returns an instance of Clientresponse.
Examples of Android and background requests