34c33e501d8cf00022d3edf7132a3f86c3b51d15.svn-base 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. package com.chinacreator.videoalliance.query.action;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.github.kevinsawicki.http.HttpRequest;
  7. import org.junit.Test;
  8. import org.springframework.beans.factory.annotation.Value;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestParam;
  11. import java.io.IOException;
  12. import java.io.InputStream;
  13. import java.nio.charset.Charset;
  14. import java.util.*;
  15. public class Npinfo2 {
  16. // private String url = "http://220.248.55.121:8888/";
  17. // private String url = " http://122.96.25.242:22098/";
  18. // private String url = "http://127.0.0.8:9898/";
  19. public String getToken() throws IOException {
  20. //String url = "http://220.248.55.121:8888/";
  21. String url = "http://210.22.123.81:8888/";
  22. String url2 = url+"oauth/token?";
  23. String username = "changshi224";
  24. String password = "1pu25ifk@81c4";
  25. // String username = "test";
  26. // String password = "o20Auf1Oc@Xb7";
  27. String grant_type = "password";
  28. String Authorization ="Basic bXktY2xpZW50Om15LXNlY3JldA==";
  29. String result;
  30. Map<String,String> param = new HashMap<String, String>();
  31. param.put("username",username);
  32. param.put("password",password);
  33. param.put("grant_type",grant_type);
  34. HttpRequest httpRequest = new HttpRequest(url2,"POST")
  35. .header("Authorization",Authorization)
  36. .contentType("application/x-www-form-urlencoded").form(param);
  37. result = new String(httpRequest.bytes(), Charset.forName("UTF-8"));
  38. // System.out.println(result);
  39. JSONObject obj = JSON.parseObject(result);
  40. String token = obj.getString("access_token");
  41. // System.out.println(token);
  42. return token;
  43. }
  44. */
  45. /**
  46. * 根据手机号码查询
  47. * @param numbers
  48. * @return
  49. *//*
  50. public String getNpInfoByNumbers(List<String> numbers) throws IOException { //携号转网号码
  51. if(numbers.size()>200){
  52. System.out.println("查询数量过大,最大查询数量为200");
  53. return "查询数量过大,最大查询数量为200";
  54. }
  55. //String url = "http://220.248.55.121:8888/";
  56. String url = "http://210.22.123.81:8888/";
  57. String url2 = url+"np/getNpInfos?";
  58. String access_token = getToken();
  59. JSONObject o = new JSONObject();
  60. o.put("serviceNums",numbers);
  61. HttpRequest httpRequest = new HttpRequest(url2+"access_token="+access_token,"POST")
  62. .contentType("application/json").send(o.toString());
  63. // System.out.println(httpRequest);
  64. String result = new String(httpRequest.bytes(), Charset.forName("UTF-8"));
  65. // System.out.println(result);
  66. JSONObject obj = JSON.parseObject(result);
  67. String code = obj.getString("code");
  68. Map<String,Object> resultmap = new LinkedHashMap<String,Object>();
  69. if("200".equals(code)){
  70. resultmap.put("resultcode","0");
  71. resultmap.put("errorinfo","");
  72. JSONArray objects = (JSONArray)obj.get("data");
  73. if(objects.size() == 0){
  74. resultmap.put("resultcode","fail");
  75. resultmap.put("errorinfo","未查询到号码转网信息");
  76. resultmap.put("data","");
  77. }
  78. List<Map<String,String>> maps = new ArrayList<Map<String, String>>();
  79. for(Object objs : objects){
  80. JSONObject data = JSON.parseObject(objs.toString()) ;
  81. String serviceNum = data.getString("serviceNum");//携号转网号码
  82. String portInId = data.getString("portInId"); //携入网络
  83. String portOutId = data.getString("portOutId"); //携出网络
  84. String serviceType = data.getString("serviceType");//业务类型:移动和固定
  85. String netType = data.getString("netType"); //网别类型:1、CDMA 2、CDMA2000 3、GSM 4、TD-SCDMA 5、WCDMA
  86. String provinceCode = data.getString("provinceCode");
  87. String instr = portInId.substring(0,3);
  88. String outstr = portOutId.substring(0,3);
  89. Map<String,String> map = new LinkedHashMap<String,String>();
  90. map.put("查询号码",serviceNum);
  91. map.put("携入网络",pdwl(instr));
  92. map.put("携出网络",pdwl(outstr));
  93. // map.put("serviceType",serviceType);
  94. // map.put("netType",netType);
  95. // map.put("provinceCode",provinceCode);
  96. maps.add(map);
  97. }
  98. // String jg = JSON.toJSONString(maps);
  99. resultmap.put("data",maps);
  100. Object oo = JSON.toJSON(resultmap);
  101. System.out.println(oo);
  102. return oo.toString();
  103. }else{
  104. resultmap.put("resultcode","fail");
  105. resultmap.put("errorinfo","查询失败");
  106. resultmap.put("data","");
  107. System.out.println("查询失败");
  108. return result;
  109. }
  110. }
  111. */
  112. /**
  113. * 根据号头查询
  114. * @param hcodes
  115. * @return
  116. *//*
  117. public String getAttrByHCodes(List<String> hcodes) throws IOException {
  118. if(hcodes.size()>200){
  119. System.out.println("查询数量过大,不能超过200");
  120. return "查询数量过大,不能超过200";
  121. }
  122. //String url = "http://220.248.55.121:8888/";
  123. String url = "http://210.22.123.81:8888/";
  124. String url2 = url+"np/getHcodesAttr?";
  125. String access_token = getToken();
  126. String result;
  127. String list;
  128. JSONObject obj = new JSONObject();
  129. obj.put("hcodes",hcodes);
  130. HttpRequest httpRequest = new HttpRequest(url2+"access_token="+access_token,"POST")
  131. .contentType("application/json").send(obj.toString());
  132. result = new String(httpRequest.bytes(), Charset.forName("UTF-8"));
  133. // System.out.println(result);
  134. JSONObject o = JSON.parseObject(result);
  135. String code = o.getString("code");
  136. System.out.println(code);
  137. Map<String,Object> resultmap = new LinkedHashMap<String,Object>();
  138. if("200".equals(code)){
  139. resultmap.put("resultcode","0");
  140. resultmap.put("errorinfo","");
  141. JSONArray objects = (JSONArray)o.get("data");
  142. List<Map<String,String>> maps = new ArrayList<Map<String,String>>();
  143. for(Object objs : objects){
  144. JSONObject data = JSON.parseObject(objs.toString());
  145. String hcode = data.getString("hcode");
  146. String province = data.getString("provinceName");
  147. String city = data.getString("cityName");
  148. Map<String,String> map = new LinkedHashMap<String,String>();
  149. map.put("查询号头",hcode);
  150. map.put("省份",province);
  151. map.put("城市",city);
  152. maps.add(map);
  153. }
  154. resultmap.put("data",maps);
  155. Object oo = JSON.toJSON(resultmap);
  156. System.out.println(oo);
  157. return oo.toString();
  158. }else{
  159. System.out.println("失败");
  160. }
  161. return result;
  162. }
  163. public String pdwl(String str){
  164. String name = "";
  165. if("001".equals(str)){
  166. name = "中国电信";
  167. }else if("002".equals(str)){
  168. name = "中国移动";
  169. }else if("003".equals(str)){
  170. name = "中国联通";
  171. }
  172. return name;
  173. }
  174. }
  175. */