• 最初的代码


    package test;

    import java.io.BufferedReader;

    import java.io.DataOutputStream;

    import java.io.IOException;

    import java.io.InputStreamReader;

    import java.io.UnsupportedEncodingException;

    import java.net.HttpURLConnection;

    import java.net.MalformedURLException;

    import java.net.URL;

    import net.sf.json.JSON;

    import net.sf.json.JSONObject;

    public class AppAddTest {

    public static final String ADD_URL = "http://115.28.189.219:9898/stock/verify_client";

    static String code = "";

    static String access_token = "";

        public static  void getCode() {

         try{

                //创建连接

                URL url = new URL(ADD_URL);

                HttpURLConnection connection = (HttpURLConnection) url.openConnection();

                connection.setDoOutput(true);

                connection.setDoInput(true);

                connection.setRequestMethod("POST");

                connection.setUseCaches(false);

                connection.setInstanceFollowRedirects(true);

                

                //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

                connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");       

                

                connection.connect();

                //POST请求

                DataOutputStream out = new DataOutputStream(connection.getOutputStream());

                

                

               //封装请求数据

                JSONObject obj = new JSONObject();

                obj.element("phone", "15110241558");

                obj.element("deviceID", "1034534545");

                obj.element("deviceType", "android");

                //System.out.println(obj.toString());

              

                //out.writeBytes(obj.toString());//这个中文会乱码

                out.write(obj.toString().getBytes("UTF-8"));//这样可以处理中文乱码问题

                out.flush();

                out.close();

                

                //读取响应

                BufferedReader reader = new BufferedReader(new InputStreamReader(

                        connection.getInputStream()));

                String lines;

                StringBuffer sb = new StringBuffer("");

                while ((lines = reader.readLine()) != null) {

                    lines = new String(lines.getBytes(), "utf-8");

                    sb.append(lines);

                }

                System.out.println(sb);

                

                

                ////////解析返回数据

                

                String retString = sb.toString();

                

                JSONObject retObject = JSONObject.fromObject(retString);

                

                System.out.println(retObject.getString("msg"));

                

                

                code = retObject.getString("msg");

                

                

        

                 

                

      

                

                

                reader.close();

                // 断开连接

                connection.disconnect();

            } catch (MalformedURLException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            } catch (UnsupportedEncodingException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            } catch (IOException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            }

        }

        

        public static void logintoken_code() {

            try{

             String logintoken_code_URL = "http://115.28.189.219:9898/oauth/token";

                   //创建连接

                   URL url = new URL(logintoken_code_URL);

                   HttpURLConnection connection = (HttpURLConnection) url.openConnection();

                   connection.setDoOutput(true);

                   connection.setDoInput(true);

                   connection.setRequestMethod("POST");

                   connection.setUseCaches(false);

                   connection.setInstanceFollowRedirects(true);

                   

                   //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

                   connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");       

                   

                   connection.connect();

                   //POST请求

                   DataOutputStream out = new DataOutputStream(connection.getOutputStream());

                   

                   

                   String accountValue = "15110241558";

                   

                   String passwordValue = "123456";

                   

                   

                 String sentdata = "grant_type=password&client_id=''&client_secret=''&username="+accountValue+"&password=" + passwordValue +"&code=" + code +"&scope=membership.internal";

                   

                      

                  //封装请求数据

    //               JSONObject obj = new JSONObject();

    //

    //               obj.element("grant_type", "password");

    //               obj.element("client_id", "");

    //               obj.element("client_secret", "");

    //               obj.element("username", "15110241558");

    //               obj.element("password", "123456");

    //               obj.element("code", code);

    //               obj.element("scope", "membership.internal");

                   //System.out.println(obj.toString());

                 

                   //out.writeBytes(obj.toString());//这个中文会乱码

                   out.write(sentdata.toString().getBytes("UTF-8"));//这样可以处理中文乱码问题

                   out.flush();

                   out.close();

                   

                   //读取响应

                   BufferedReader reader = new BufferedReader(new InputStreamReader(

                           connection.getInputStream()));

                   String lines;

                   StringBuffer sb = new StringBuffer("");

                   while ((lines = reader.readLine()) != null) {

                       lines = new String(lines.getBytes(), "utf-8");

                       sb.append(lines);

                   }

                   System.out.println(sb);

                   

                   

                   ////////解析返回数据

                   

                   String retString = sb.toString();

                   

                   JSONObject retObject = JSONObject.fromObject(retString);

                   

                   System.out.println(retObject.getString("access_token"));

                   

                   access_token = retObject.getString("access_token");

                   

                   

           

                    

                   

         

                   

                   

                   reader.close();

                   // 断开连接

                   connection.disconnect();

               } catch (MalformedURLException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               } catch (UnsupportedEncodingException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               } catch (IOException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               }

           }

        public static  void getMe() {

            try{

            String getMe_URL = "http://115.28.189.219:9898/stock/me?access_token="+access_token;

                   //创建连接

                   URL url = new URL(getMe_URL);

                   HttpURLConnection connection = (HttpURLConnection) url.openConnection();

                   connection.setDoOutput(true);

                   connection.setDoInput(true);

                   connection.setRequestMethod("GET");

                   connection.setUseCaches(false);

                   connection.setInstanceFollowRedirects(true);

                   

                   //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

                   connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");       

                   

                   connection.connect();

                   

                   //读取响应

                   BufferedReader reader = new BufferedReader(new InputStreamReader(

                           connection.getInputStream()));

                   String lines;

                   StringBuffer sb = new StringBuffer("");

                   while ((lines = reader.readLine()) != null) {

                       lines = new String(lines.getBytes(), "utf-8");

                       sb.append(lines);

                   }

                   System.out.println(sb);

                   

                   

                   ////////解析返回数据

                   

                   String retString = sb.toString();

                   

                   JSONObject retObject = JSONObject.fromObject(retString);

                   

                   System.out.println(retObject.getString("balance"));

                   

                   

                   reader.close();

                   // 断开连接

                   connection.disconnect();

               } catch (MalformedURLException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               } catch (UnsupportedEncodingException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               } catch (IOException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               }

           }

        public static void main(String[] args) {

        getCode();

        logintoken_code();

        getMe();

        }

    }

        public static  void ChangePlayerInfo() {

         try{

                //创建连接

                URL url = new URL(ChangePlayerInfo_URL);

                HttpURLConnection connection = (HttpURLConnection) url.openConnection();

                connection.setDoOutput(true);

                connection.setDoInput(true);

                connection.setRequestMethod("POST");

                connection.setUseCaches(false);

                connection.setInstanceFollowRedirects(true);

                

                //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

                connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");       

                

                connection.connect();

                //POST请求

                DataOutputStream out = new DataOutputStream(connection.getOutputStream());

                

                

               //封装请求数据

                JSONObject obj = new JSONObject();

                obj.element("nickname", "豆豆");

                obj.element("sex", "男");

                obj.element("desc", "瞎操作");

                //System.out.println(obj.toString());

              

                //out.writeBytes(obj.toString());//这个中文会乱码

                out.write(obj.toString().getBytes("UTF-8"));//这样可以处理中文乱码问题

                out.flush();

                out.close();

                

                //读取响应

                BufferedReader reader = new BufferedReader(new InputStreamReader(

                        connection.getInputStream()));

                String lines;

                StringBuffer sb = new StringBuffer("");

                while ((lines = reader.readLine()) != null) {

                    lines = new String(lines.getBytes(), "utf-8");

                    sb.append(lines);

                }

                System.out.println(sb);

                

                

                ////////解析返回数据

                

                String retString = sb.toString();

                

                JSONObject retObject = JSONObject.fromObject(retString);

                

                System.out.println(retObject.getString("msg"));

                

                

                code = retObject.getString("msg");

                

                

        

                 

                

      

                

                

                reader.close();

                // 断开连接

                connection.disconnect();

            } catch (MalformedURLException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            } catch (UnsupportedEncodingException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            } catch (IOException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            }

        }

    public static  void myInvestment() {

            try{

            String myInvestment_URL = "http://115.28.189.219:9898/stock/products?access_token="+access_token;

                   //创建连接

                   URL url = new URL(myInvestment_URL);

                   HttpURLConnection connection = (HttpURLConnection) url.openConnection();

                   connection.setDoOutput(true);

                   connection.setDoInput(true);

                   connection.setRequestMethod("GET");

                   connection.setUseCaches(false);

                   connection.setInstanceFollowRedirects(true);

                   

                   //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

                   connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");       

                   

                   connection.connect();

                   

                   //读取响应

                   BufferedReader reader = new BufferedReader(new InputStreamReader(

                           connection.getInputStream()));

                   String lines;

                   StringBuffer sb = new StringBuffer("");

                   while ((lines = reader.readLine()) != null) {

                       lines = new String(lines.getBytes(), "utf-8");

                       sb.append(lines);

                   }

                   System.out.println(sb);

                   

                   

                   ////////解析返回数据

                   

                   String retString = sb.toString();

                   

                   JSONObject retObject = JSONObject.fromObject(retString);

                   

                   System.out.println(retObject.getString("balance"));

                   

                   

                   reader.close();

                   // 断开连接

                   connection.disconnect();

               } catch (MalformedURLException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               } catch (UnsupportedEncodingException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               } catch (IOException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               }

    [股价查询:stock] ---------->api url stock/stock/{investmentId}/{code} 

    Response:{"name":"梅雁吉祥","price":571,"date":"2016-04-13T20:34:17Z","availableQuantity":0} 

    [买卖股票(买):createPosition] ---------->api url stock/stocks ,post {"quantity":500,"dealType":"Buy","price":500,"code":"600868","productId":189} 

    Response:{"code":0,"msg":""} 

    public static void :createPosition_code() {

            try{

             String :createPosition_code_URL = "http://115.28.189.219:9898/stock/stocks/token";

                   //创建连接

                   URL url = new URL(createPosition_code_URL);

                   HttpURLConnection connection = (HttpURLConnection) url.openConnection();

                   connection.setDoOutput(true);

                   connection.setDoInput(true);

                   connection.setRequestMethod("POST");

                   connection.setUseCaches(false);

                   connection.setInstanceFollowRedirects(true);

                   

                   //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

                   connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");       

                   

                   connection.connect();

                   //POST请求

                   DataOutputStream out = new DataOutputStream(connection.getOutputStream());

                   

                   

                      

                  //封装请求数据

                  JSONObject obj = new JSONObject();

                  obj.element("quantity", 500);

                  obj.element("dealType", "Buy");

                  obj.element("price", 400);

                  obj.element("code", "600868");

                  obj.element("productId", 189);

                   //System.out.println(obj.toString());

                 

                   //out.writeBytes(obj.toString());//这个中文会乱码

                   out.write(sentdata.toString().getBytes("UTF-8"));//这样可以处理中文乱码问题

                   out.flush();

                   out.close();

                   

                   //读取响应

                   BufferedReader reader = new BufferedReader(new InputStreamReader(

                           connection.getInputStream()));

                   String lines;

                   StringBuffer sb = new StringBuffer("");

                   while ((lines = reader.readLine()) != null) {

                       lines = new String(lines.getBytes(), "utf-8");

                       sb.append(lines);

                   }

                   System.out.println(sb);

                   

                   

                   ////////解析返回数据

                   

                   String retString = sb.toString();

                   

                   JSONObject retObject = JSONObject.fromObject(retString);

                   

                   System.out.println(retObject.getString("access_token"));

                   

                   access_token = retObject.getString("access_token");

                   

                   

           

                    

                   

         

                   

                   

                   reader.close();

                   // 断开连接

                   connection.disconnect();

               } catch (MalformedURLException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               } catch (UnsupportedEncodingException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               } catch (IOException e) {

                   // TODO Auto-generated catch block

                   e.printStackTrace();

               }

           }

    &date=2016-01-01T00:00:00Z[验证码:verify_client] ---------->api url stock/verify_client ,post {"phone":"1460630091572","deviceID":"aC8Aa7CLYKjkN8SlJNU9jmCKR8P_hyCh","deviceType":"android"} 
    , response:{"code":0,"msg":"1942"} 


    [登录:token_code] ---------->api url oauth/token ,post FormData(List((grant_type,password), (client_id,), (client_secret,), (code,1942), (username,1460630091572), (password,1460630091572), (scope,membership.internal))) 
    , response:{"access_token":"WudYqKDKzijeMcrmYcP.qFiGgIavFs0u","expires_in":3599,"scope":"membership.internal","refresh_token":"kRMkWXd8CNwQn3icPr0Cb0k2wPCULGxiMVNHwkRXkPjMQRBS","token_type":"Bearer","client_id":"55","client_secret":"eCdTHlDbXoJ298dA.b4xQIWvyuE.8.l3"}

    [我:me] ---------->api url stock/me 
    with token:WudYqKDKzijeMcrmYcP.qFiGgIavFs0u response:{"desc":"","name":"1460630091572","balance":100000000,"sex":"","nickName":"1460630091572","logo":"http://115.28.189.219/player_icon/19.png","watched":0,"phone":""} 

    初步认识:Java接口编程需要有逻辑性,也是按照业务流程来完成的

    package test;import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;
    import net.sf.json.JSON;
    import net.sf.json.JSONObject;
    public class AppAddTest {public static final String ADD_URL = "http://115.28.189.219:9898/stock/verify_client";static String code = "";static String access_token = "";
        public static  void getCode() {
         try{            //创建连接            URL url = new URL(ADD_URL);            HttpURLConnection connection = (HttpURLConnection) url.openConnection();            connection.setDoOutput(true);            connection.setDoInput(true);            connection.setRequestMethod("POST");            connection.setUseCaches(false);            connection.setInstanceFollowRedirects(true);                        //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");            connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");                               connection.connect();
                //POST请求            DataOutputStream out = new DataOutputStream(connection.getOutputStream());                                   //封装请求数据            JSONObject obj = new JSONObject();
                obj.element("phone", "15110241558");            obj.element("deviceID", "1034534545");            obj.element("deviceType", "android");            //System.out.println(obj.toString());                      //out.writeBytes(obj.toString());//这个中文会乱码            out.write(obj.toString().getBytes("UTF-8"));//这样可以处理中文乱码问题            out.flush();            out.close();                        //读取响应            BufferedReader reader = new BufferedReader(new InputStreamReader(                    connection.getInputStream()));            String lines;            StringBuffer sb = new StringBuffer("");            while ((lines = reader.readLine()) != null) {                lines = new String(lines.getBytes(), "utf-8");                sb.append(lines);            }            System.out.println(sb);                                    ////////解析返回数据                        String retString = sb.toString();                        JSONObject retObject = JSONObject.fromObject(retString);                        System.out.println(retObject.getString("msg"));                                    code = retObject.getString("msg");                                                                                           reader.close();            // 断开连接            connection.disconnect();        } catch (MalformedURLException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (UnsupportedEncodingException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (IOException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }
        }        public static void logintoken_code() {
            try{         String logintoken_code_URL = "http://115.28.189.219:9898/oauth/token";               //创建连接               URL url = new URL(logintoken_code_URL);               HttpURLConnection connection = (HttpURLConnection) url.openConnection();               connection.setDoOutput(true);               connection.setDoInput(true);               connection.setRequestMethod("POST");               connection.setUseCaches(false);               connection.setInstanceFollowRedirects(true);                              //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");               connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");                                     connection.connect();
                   //POST请求               DataOutputStream out = new DataOutputStream(connection.getOutputStream());                                             String accountValue = "15110241558";                              String passwordValue = "123456";                                           String sentdata = "grant_type=password&client_id=''&client_secret=''&username="+accountValue+"&password=" + passwordValue +"&code=" + code +"&scope=membership.internal";                                               //封装请求数据//               JSONObject obj = new JSONObject();////               obj.element("grant_type", "password");//               obj.element("client_id", "");//               obj.element("client_secret", "");//               obj.element("username", "15110241558");//               obj.element("password", "123456");//               obj.element("code", code);//               obj.element("scope", "membership.internal");               //System.out.println(obj.toString());                            //out.writeBytes(obj.toString());//这个中文会乱码               out.write(sentdata.toString().getBytes("UTF-8"));//这样可以处理中文乱码问题               out.flush();               out.close();                              //读取响应               BufferedReader reader = new BufferedReader(new InputStreamReader(                       connection.getInputStream()));               String lines;               StringBuffer sb = new StringBuffer("");               while ((lines = reader.readLine()) != null) {                   lines = new String(lines.getBytes(), "utf-8");                   sb.append(lines);               }               System.out.println(sb);                                             ////////解析返回数据                              String retString = sb.toString();                              JSONObject retObject = JSONObject.fromObject(retString);                              System.out.println(retObject.getString("access_token"));                              access_token = retObject.getString("access_token");                                                                                                                      reader.close();               // 断开连接               connection.disconnect();           } catch (MalformedURLException e) {               // TODO Auto-generated catch block               e.printStackTrace();           } catch (UnsupportedEncodingException e) {               // TODO Auto-generated catch block               e.printStackTrace();           } catch (IOException e) {               // TODO Auto-generated catch block               e.printStackTrace();           }
           }
        public static  void getMe() {
            try{        String getMe_URL = "http://115.28.189.219:9898/stock/me?access_token="+access_token;               //创建连接               URL url = new URL(getMe_URL);               HttpURLConnection connection = (HttpURLConnection) url.openConnection();               connection.setDoOutput(true);               connection.setDoInput(true);               connection.setRequestMethod("GET");               connection.setUseCaches(false);               connection.setInstanceFollowRedirects(true);                              //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");               connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");                                     connection.connect();

                                  //读取响应               BufferedReader reader = new BufferedReader(new InputStreamReader(                       connection.getInputStream()));               String lines;               StringBuffer sb = new StringBuffer("");               while ((lines = reader.readLine()) != null) {                   lines = new String(lines.getBytes(), "utf-8");                   sb.append(lines);               }               System.out.println(sb);                                             ////////解析返回数据                              String retString = sb.toString();                              JSONObject retObject = JSONObject.fromObject(retString);                              System.out.println(retObject.getString("balance"));                                             reader.close();               // 断开连接               connection.disconnect();           } catch (MalformedURLException e) {               // TODO Auto-generated catch block               e.printStackTrace();           } catch (UnsupportedEncodingException e) {               // TODO Auto-generated catch block               e.printStackTrace();           } catch (IOException e) {               // TODO Auto-generated catch block               e.printStackTrace();           }
           }    public static void main(String[] args) {    getCode();    logintoken_code();    getMe();    }}







        public static  void ChangePlayerInfo() {
         try{            //创建连接            URL url = new URL(ChangePlayerInfo_URL);            HttpURLConnection connection = (HttpURLConnection) url.openConnection();            connection.setDoOutput(true);            connection.setDoInput(true);            connection.setRequestMethod("POST");            connection.setUseCaches(false);            connection.setInstanceFollowRedirects(true);                        //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");            connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");                               connection.connect();
                //POST请求            DataOutputStream out = new DataOutputStream(connection.getOutputStream());                                   //封装请求数据            JSONObject obj = new JSONObject();
                obj.element("nickname", "豆豆");            obj.element("sex", "男");            obj.element("desc", "瞎操作");            //System.out.println(obj.toString());                      //out.writeBytes(obj.toString());//这个中文会乱码            out.write(obj.toString().getBytes("UTF-8"));//这样可以处理中文乱码问题            out.flush();            out.close();                        //读取响应            BufferedReader reader = new BufferedReader(new InputStreamReader(                    connection.getInputStream()));            String lines;            StringBuffer sb = new StringBuffer("");            while ((lines = reader.readLine()) != null) {                lines = new String(lines.getBytes(), "utf-8");                sb.append(lines);            }            System.out.println(sb);                                    ////////解析返回数据                        String retString = sb.toString();                        JSONObject retObject = JSONObject.fromObject(retString);                        System.out.println(retObject.getString("msg"));                                    code = retObject.getString("msg");                                                                                           reader.close();            // 断开连接            connection.disconnect();        } catch (MalformedURLException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (UnsupportedEncodingException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (IOException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }
        }
    public static  void myInvestment() {
            try{        String myInvestment_URL = "http://115.28.189.219:9898/stock/products?access_token="+access_token;               //创建连接               URL url = new URL(myInvestment_URL);               HttpURLConnection connection = (HttpURLConnection) url.openConnection();               connection.setDoOutput(true);               connection.setDoInput(true);               connection.setRequestMethod("GET");               connection.setUseCaches(false);               connection.setInstanceFollowRedirects(true);                              //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");               connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");                                     connection.connect();

                                  //读取响应               BufferedReader reader = new BufferedReader(new InputStreamReader(                       connection.getInputStream()));               String lines;               StringBuffer sb = new StringBuffer("");               while ((lines = reader.readLine()) != null) {                   lines = new String(lines.getBytes(), "utf-8");                   sb.append(lines);               }               System.out.println(sb);                                             ////////解析返回数据                              String retString = sb.toString();                              JSONObject retObject = JSONObject.fromObject(retString);                              System.out.println(retObject.getString("balance"));                                             reader.close();               // 断开连接               connection.disconnect();           } catch (MalformedURLException e) {               // TODO Auto-generated catch block               e.printStackTrace();           } catch (UnsupportedEncodingException e) {               // TODO Auto-generated catch block               e.printStackTrace();           } catch (IOException e) {               // TODO Auto-generated catch block               e.printStackTrace();           }

    [股价查询:stock] ---------->api url stock/stock/{investmentId}/{code} Response:{"name":"梅雁吉祥","price":571,"date":"2016-04-13T20:34:17Z","availableQuantity":0} 

    [买卖股票(买):createPosition] ---------->api url stock/stocks ,post {"quantity":500,"dealType":"Buy","price":500,"code":"600868","productId":189} Response:{"code":0,"msg":""} 


    public static void :createPosition_code() {
            try{         String :createPosition_code_URL = "http://115.28.189.219:9898/stock/stocks/token";               //创建连接               URL url = new URL(createPosition_code_URL);               HttpURLConnection connection = (HttpURLConnection) url.openConnection();               connection.setDoOutput(true);               connection.setDoInput(true);               connection.setRequestMethod("POST");               connection.setUseCaches(false);               connection.setInstanceFollowRedirects(true);                              //connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");               connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");                                     connection.connect();
                   //POST请求               DataOutputStream out = new DataOutputStream(connection.getOutputStream());                                                              //封装请求数据              JSONObject obj = new JSONObject();
                  obj.element("quantity", 500);              obj.element("dealType", "Buy");              obj.element("price", 400);              obj.element("code", "600868");              obj.element("productId", 189);               //System.out.println(obj.toString());                            //out.writeBytes(obj.toString());//这个中文会乱码               out.write(sentdata.toString().getBytes("UTF-8"));//这样可以处理中文乱码问题               out.flush();               out.close();                              //读取响应               BufferedReader reader = new BufferedReader(new InputStreamReader(                       connection.getInputStream()));               String lines;               StringBuffer sb = new StringBuffer("");               while ((lines = reader.readLine()) != null) {                   lines = new String(lines.getBytes(), "utf-8");                   sb.append(lines);               }               System.out.println(sb);                                             ////////解析返回数据                              String retString = sb.toString();                              JSONObject retObject = JSONObject.fromObject(retString);                              System.out.println(retObject.getString("access_token"));                              access_token = retObject.getString("access_token");                                                                                                                      reader.close();               // 断开连接               connection.disconnect();           } catch (MalformedURLException e) {               // TODO Auto-generated catch block               e.printStackTrace();           } catch (UnsupportedEncodingException e) {               // TODO Auto-generated catch block               e.printStackTrace();           } catch (IOException e) {               // TODO Auto-generated catch block               e.printStackTrace();           }
           }










    [买卖股票(卖):createPosition] ---------->api url stock/stocks ,post {"quantity":500,"dealType":"Sell","price":500,"code":"600868","productId":189} Response:{"code":1003,"msg":"错误[股票600868可卖数量不够]"} 

    [投资组合内容:investmentDetail] ---------->api url stock/products/{productId} Response:{"desc":"desc","yieldsWeek":[],"stocks":[{"name":"梅雁吉祥","quantity":500,"returnRate":"+14.20%","totalMarket":285500,"marketPrice":571,"code":"600868","availableQuantity":0,"costPrice":500}],"yearReturnRate":"0.00%","totalBalance":5035500,"totalStockBalance":285500,"price":9999,"balance":4750000,"initBalance":5000000,"productId":189,"monthReturnRate":"0.00%","positionRate":"5.67%","watched":0,"created":"2016-04-14T08:34:17Z"} 

    [交易历史:investmentTransactions] ---------->api url stock/stock_transactions/{productId} Response:[{"name":"梅雁吉祥","quantity":500,"dealType":"Buy","price":500,"code":"600868","created":"2016-04-14T08:34:17Z"}] 

    [创建消息:createInfo] ---------->api url stock/infos ,post {"productId":189,"title":"测试消息标题","content":"测试消息内容"} Response:{"code":0,"msg":""} 

    [消息历史:investmentInfos] ---------->api url stock/infos/{productId} Response:[{"id":256,"title":"买入操作:投资组合[test investment]","date":"2016-04-14T08:34:17Z"},{"id":257,"title":"测试消息标题","date":"2016-04-14T08:34:17Z"}] 

    [消息内容:info] ---------->api url stock/info/{infoId} Response:{"title":"买入操作:投资组合[test investment]","date":"2016-04-14T08:34:17Z","content":"投资组合[test investment]买入证券[600868],数量500"} 

    [大师排行:masterRanks] ---------->api url stock/masters_rank Response:[{"desc":"看李某某;潜力股;长线投资;短线投资;控股;股票投入","returnRate":"","balance":100390076,"logo":"http://115.28.189.219/player_icon/19.png","id":107,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"豆丁"},{"desc":"中华精选一百期;践行价值投资;desc","returnRate":"","balance":100071500,"logo":"http://115.28.189.219/player_icon/19.png","id":95,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1450949146527"},{"desc":"desc","returnRate":"","balance":100027000,"logo":"http://115.28.189.219/player_icon/19.png","id":24,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1441173786486"},{"desc":"desc","returnRate":"","balance":100018000,"logo":"http://115.28.189.219/player_icon/19.png","id":25,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1441173873436"},{"desc":"desc","returnRate":"","balance":100018000,"logo":"http://115.28.189.219/player_icon/19.png","id":26,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1441174069771"},{"desc":"desc","returnRate":"","balance":100017500,"logo":"http://115.28.189.219/player_icon/19.png","id":36,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1441178431420"},{"desc":"desc","returnRate":"","balance":100009000,"logo":"http://115.28.189.219/player_icon/19.png","id":27,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1441174644496"},{"desc":"desc","returnRate":"","balance":100009000,"logo":"http://115.28.189.219/player_icon/19.png","id":28,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1441174969672"},{"desc":"desc","returnRate":"","balance":100009000,"logo":"http://115.28.189.219/player_icon/19.png","id":30,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1441175639782"},{"desc":"desc","returnRate":"","balance":100009000,"logo":"http://115.28.189.219/player_icon/19.png","id":31,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1441176088002"},{"desc":"desc","returnRate":"","balance":100009000,"logo":"http://115.28.189.219/player_icon/19.png","id":40,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1442289902822"},{"desc":"desc","returnRate":"","balance":100009000,"logo":"http://115.28.189.219/player_icon/19.png","id":41,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1442290030599"},{"desc":"desc","returnRate":"","balance":100009000,"logo":"http://115.28.189.219/player_icon/19.png","id":42,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1442290638307"},{"desc":"desc","returnRate":"","balance":100009000,"logo":"http://115.28.189.219/player_icon/19.png","id":44,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1442312845894"},{"desc":"desc","returnRate":"","balance":100008500,"logo":"http://115.28.189.219/player_icon/19.png","id":33,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1441177715723"},{"desc":"desc","returnRate":"","balance":100008500,"logo":"http://115.28.189.219/player_icon/19.png","id":35,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1441178000150"},{"desc":"desc","returnRate":"","balance":100008500,"logo":"http://115.28.189.219/player_icon/19.png","id":51,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1446547230322"},{"desc":"desc","returnRate":"","balance":100008500,"logo":"http://115.28.189.219/player_icon/19.png","id":52,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1447767300612"},{"desc":"desc","returnRate":"","balance":100008500,"logo":"http://115.28.189.219/player_icon/19.png","id":68,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1449482035714"},{"desc":"desc","returnRate":"","balance":100008500,"logo":"http://115.28.189.219/player_icon/icon_70.gif","id":70,"treasureName":"金币","isWatched":false,"watched":0,"nickname":"1449633083712"}] 

    [关注大师:watchMaster] ---------->api url stock/masters ,post {"masterId":107,"remarks":"很有价值","watched":true} Response:{"code":0,"msg":""} 

    [大师的投资组合:masterInvestments] ---------->api url stock/masters/{masterId} Response:[{"desc":"股票投入","name":"股票","price":100,"returnRate":"","id":102,"initBalance":20000000,"createdAt":"2016-01-28T23:23:14Z","isWatched":false,"watched":0},{"desc":"短线投资","name":"九安医疗","price":200,"returnRate":"","id":129,"initBalance":5000000,"createdAt":"2016-03-11T02:00:20Z","isWatched":false,"watched":0},{"desc":"长线投资","name":"大智慧","price":100,"returnRate":"","id":130,"initBalance":1000000,"createdAt":"2016-03-11T02:01:24Z","isWatched":false,"watched":0},{"desc":"潜力股","name":"长线投资","price":1000,"returnRate":"","id":132,"initBalance":100000000,"createdAt":"2016-03-11T02:41:18Z","isWatched":false,"watched":0},{"desc":"看李某某","name":"军工板块","price":500000,"returnRate":"","id":133,"initBalance":100000000,"createdAt":"2016-03-11T03:28:30Z","isWatched":false,"watched":0},{"desc":"控股","name":"农业板块","price":1000,"returnRate":"","id":134,"initBalance":20000000,"createdAt":"2016-03-11T03:40:45Z","isWatched":false,"watched":0}] 

    [关注投资组合:watchInvestment] ---------->api url stock/orders ,post {"productId":102} Response:{"code":0,"msg":""} 

    [我关注的大师:watchedMasters] ---------->api url stock/masters Response:[{"desc":"短线投资;控股;股票投入;看李某某;潜力股;长线投资","returnRate":"","balance":100390166,"logo":"http://115.28.189.219/player_icon/19.png","id":107,"treasureName":"金币","isWatched":true,"watched":0,"nickname":"豆丁"}] 

    [关注大师(取消):watchMaster] ---------->api url stock/masters ,post {"masterId":107,"remarks":"很有价值","watched":false} Response:{"code":2,"msg":"system error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' and friend = 107, and game = 100' at line 1"} 

    [关注消息:watchedInfos] ---------->api url stock/infos Response:[] 

    [资讯目录:articleCategories] ---------->api url stock/categories Response:[{"id":1,"name":"要闻","code":"fundamentals","needLogin":false},{"id":2,"name":"公司","code":"company","needLogin":true},{"id":100,"name":"投资","code":"investment","needLogin":true}] 

    [资讯列表:articles] ---------->api url stock/articles/{code} Response:{"articles":[{"icon":"http://115.28.189.219/article_icon/icon_36.png","id":36,"date":"2016-03-18T10:22:33Z","title":"炒股实战招数","contentUrl":"http://shizhanshizhao.flzhan.com/text6.html?rd=0.3939783030655235","summary":"实战逃顶十二招,招招都很实用","needLogin":false},{"icon":"http://115.28.189.219/article_icon/icon_35.png","id":35,"date":"2016-03-18T10:01:45Z","title":"炒股实战","contentUrl":"http://shizhanshizhao.flzhan.com/text6.html?rd=0.9021269986405969","summary":"实战逃顶十二招,招招都很实用","needLogin":false},{"icon":"http://115.28.189.219/article_icon/icon_34.jpg","id":34,"date":"2016-03-18T04:53:25Z","title":"炒股实战","contentUrl":"http://gupiaotupian.flzhan.com/text40.html?rd=0.13897111429832876","summary":"实战逃顶十招","needLogin":false},{"icon":"http://115.28.189.219/article_icon/icon_33.jpg","id":33,"date":"2016-02-04T12:16:24Z","title":"东方时尚明日登陆上交所","contentUrl":"http://shopling.flzhan.com/text1.html?rd=0.9364715619012713","summary":"驾校第一股全解析","needLogin":false},{"icon":"http://115.28.189.219/article_icon/icon_31.jpg","id":31,"date":"2016-02-04T11:56:52Z","title":"沪指尾盘拉升","contentUrl":"http://treasure.flzhan.com/text53.html?rd=0.7120060743764043","summary":"创业板表现较为强势","needLogin":false},{"icon":"http://115.28.189.219/article_icon/icon_29.png","id":29,"date":"2016-02-04T06:17:25Z","title":"股票基金","contentUrl":"http://treasure.flzhan.com/text22.html?rd=0.987254434498027","summary":"基金","needLogin":false}],"topArticles":[{"icon":"http://115.28.189.219/article_icon/icon_11.jpg","id":11,"date":"2016-03-18T05:52:16Z","title":"万科紧急停牌:筹划发行","contentUrl":"新浪财经讯 午间,万科发布公告称,因正在筹划股份发行用于重大资产重组及收购资产,午后AH股临时停牌。早盘,万科A报24.43元/股,股价涨停,12月份以来,万科A(24.43, 2.22, 10.00%)股价上涨接近70%。万科H股(万科企业,02202.HK)早盘涨2%。   目前,宝能系收购万科事件持续发酵,王石指不欢迎宝能系成为万科第一大股东;宝能强调相信市场力量。   万科午间公告   因万科企业股份有限公司正在筹划股份发行,用于重大资产重组及收购资产,根据《深圳证券交易所股票上市规则》的有关规定,经公司申请,该公司股票(证券简称:万科A,证券代码:000002)自2015年12月18日下午13:00起停牌,待公司刊登相关公告后复牌。","summary":"央行今日开展100亿7","needLogin":false},{"icon":"http://115.28.189.219/article_icon/icon_9.jpg","id":9,"date":"2016-03-18T05:40:41Z","title":"万科紧急停牌:筹划发行","contentUrl":"新浪财经讯 午间,万科发布公告称,因正在筹划股份发行用于重大资产重组及收购资产,午后AH股临时停牌。早盘,万科A报24.43元/股,股价涨停,12月份以来,万科A(24.43, 2.22, 10.00%)股价上涨接近70%。万科H股(万科企业,02202.HK)早盘涨2%。   目前,宝能系收购万科事件持续发酵,王石指不欢迎宝能系成为万科第一大股东;宝能强调相信市场力量。   万科午间公告   因万科企业股份有限公司正在筹划股份发行,用于重大资产重组及收购资产,根据《深圳证券交易所股票上市规则》的有关规定,经公司申请,该公司股票(证券简称:万科A,证券代码:000002)自2015年12月18日下午13:00起停牌,待公司刊登相关公告后复牌。","summary":"央行今日开展100亿7","needLogin":false},{"icon":"http://115.28.189.219/article_icon/icon_10.jpg","id":10,"date":"2016-02-04T11:49:56Z","title":"万科紧急停牌:筹划发行","contentUrl":"新浪财经讯 午间,万科发布公告称,因正在筹划股份发行用于重大资产重组及收购资产,午后AH股临时停牌。早盘,万科A报24.43元/股,股价涨停,12月份以来,万科A(24.43, 2.22, 10.00%)股价上涨接近70%。万科H股(万科企业,02202.HK)早盘涨2%。   目前,宝能系收购万科事件持续发酵,王石指不欢迎宝能系成为万科第一大股东;宝能强调相信市场力量。   万科午间公告   因万科企业股份有限公司正在筹划股份发行,用于重大资产重组及收购资产,根据《深圳证券交易所股票上市规则》的有关规定,经公司申请,该公司股票(证券简称:万科A,证券代码:000002)自2015年12月18日下午13:00起停牌,待公司刊登相关公告后复牌。","summary":"央行今日开展100亿7","needLogin":false}]} 

    [资讯内容:article] ---------->api url stock/article/{categoryCode}/{articleId} Response:HttpEntity(text/html; charset=UTF-8,炒股实战招数
    http://shizhanshizhao.flzhan.com/text6.html?rd=0.3939783030655235) 

    [创建反馈:createFeedback] ---------->api url stock/feedbacks ,post {"content":"这个游戏很好啊,值得大力推广","email":""} Response:{"code":0,"msg":""} 

     

  • 相关阅读:
    jquery基本用法
    js里BOM和DOM操作
    js基础语法
    java将json格式的字符串转化为对象数组
    Java生成Excel并导入数据
    mybatis的xml中使用foreach循环拼接(sql中的 in 语法)
    FreeMarker在List中取任意一条数据的某一个值
    freemarker中的常用语法
    Java将日期转化为大写格式(阿拉伯大写数字)
    项目中出现The import javax.servlet cannot be resolved 的解决方法
  • 原文地址:https://www.cnblogs.com/fenr9/p/5394144.html
Copyright © 2020-2023  润新知