我的日常

登录/注册
您现在的位置:论坛 盖世程序员(我猜到了开头 却没有猜到结局) 项目源码 > 小Q机器人之大黄鸡java版本
总共48087条微博

动态微博

查看: 3983|回复: 5

小Q机器人之大黄鸡java版本

[复制链接]
admin    

1244

主题

544

听众

1万

金钱

管理员

  • TA的每日心情

    2021-2-2 11:21
  • 签到天数: 36 天

    [LV.5]常住居民I

    管理员

    跳转到指定楼层
    楼主
    发表于 2014-10-18 09:11:12 |只看该作者 |倒序浏览
    小Q机器人之大黄鸡java版本:自定义回复、查询天气、调用小黄鸡、、、版本采用webQQ3.0协议: w/ c$ R$ G7 {7 u7 T
    登陆类:Login.java
    , q1 B9 N& l, ]& W- S' [; \
    1. public class Login {. l6 g% [3 ^8 ^. Q+ r+ ]1 u% v7 {
    2.     public static void main(String[] args) {
      / l& V9 |& R9 _* O% A6 E2 G
    3.         //获取配置
      ; Z/ V! _. o2 _0 ?
    4.         Config config = Config.getInstance();
      5 g5 t) E1 n: l3 N6 o- l- q
    5.         String qqName = config.getQQ();
      4 m1 A: e, a2 ~$ X
    6.         String password = config.getPassword();% c, m1 Y) N# p+ P# z* p# N, }
    7.         WebQQClientStart qq = new WebQQClientStart(qqName, password);  m+ R0 w% P8 p8 f8 r) Z: _  y
    8.         //登录% G) Q3 V5 r6 K% e) ]7 P' j
    9.         qq.login();7 N3 z  T5 p, F% I" ^. r7 d
    10.     }
      " J7 i0 W3 Y" t
    11. }
    复制代码
    配置QQ号密码Config.java:# E; D% N5 Z# I# U# U
    1. public class Config {
      1 j- M: z2 A9 f( s9 U8 Y
    2. 7 t7 n" @( M9 A0 |+ ]! P9 k2 |3 D) }
    3.     private static class ConfigInstance {
      ' d/ [( Q; n' b2 D0 C9 p

    4. & a( g& c: P& e0 X
    5.         private static final Config INSTANCE = new Config();' ~! _3 S. ^" [
    6.     }; l- O+ k+ H6 z) \* d$ _! T) f1 y( n
    7. 5 r9 K7 b4 P# K8 T( m0 m0 t
    8.     /**
      & o1 K9 Q8 P. h8 f7 o3 \3 p" _
    9.      * 配置文件地址! Q! A  X7 }* c+ c) X3 o3 c1 g
    10.      */
      4 t: a# x6 q: D- j
    11.     private static final String PROPERTIES = "config.properties";
        X" ^0 A5 o& P4 |9 v% m3 Z
    12. % M) J! d- ~) n; ]6 e, t2 |" J7 N7 h
    13.     private String qq;
      " }/ ]  \, E3 \

    14. 2 B& g2 b# ~1 k3 a+ y: ~
    15.     private String password;
      + E. ^1 H: u" f
    16.     6 D. d% ]5 V5 p; T' r' d6 S" Q

    17. + I7 A' u. [2 z: M: T  j
    18.     private Config() {
      5 Z3 Q- S: N# C: U& F2 e& l
    19.         //读取配置对象: w' y/ T5 Q6 j
    20.         Properties pro = new Properties();4 x' u* D! b3 ~! e6 ^" k; {
    21.         try {
      7 F' D% Q4 i3 M9 T4 O
    22.             pro.load(new FileInputStream(PROPERTIES));  s% G& C. i7 [- ?* U4 h0 {" ?; }
    23.         } catch (IOException ex) {
      8 A8 z, j4 e! z4 D; d% ~
    24.             ex.printStackTrace();3 D6 H0 P$ I. |$ d- P
    25.             System.exit(1);
      % k  o9 J9 `3 c2 C
    26.         }4 ~& Y4 o, E: w7 }* O8 H* [; |
    27.         this.setQQ(pro.getProperty("QQ"));1 F7 ^5 u7 `# P; e6 Q
    28.         this.setPassword(pro.getProperty("PASSWORD"));7 A: t8 C) K- Y9 u( b
    29.     }8 I" ^5 S. I5 y
    30.     public String getQQ() {9 L1 T7 z5 C. P2 V5 O
    31.         return qq;
      4 n8 ]: R# o. `# T( b
    32.     }
      ( l. s& U7 z% j

    33. : u+ A5 z$ n( w9 u
    34.     private void setQQ(String qq) {  z8 c" {; \+ k+ g! [% l# n8 ^
    35.         if (qq.isEmpty()) {6 _. O) W+ R9 o; _- S- w
    36.           System.out.println("必须在config.properties中填写QQ号!");* M% n3 m+ g5 t( g% N1 |
    37.         }9 k) K$ v! @) W, j3 O: H$ o+ y
    38.         this.qq = qq;9 B/ V  ?6 l; b% K
    39.     }
      ' L- S' k1 \$ i+ _) |0 v
    40. ' @, e( o7 [- R
    41.     public String getPassword() {
      / I4 {# b( C1 F6 d
    42.         return password;* |" g. `' [, Y" b
    43.     }
      6 S6 L4 ~) X6 H5 c7 t
    44. 2 G( ]: |4 ?5 L# ~" U
    45.     private void setPassword(String password) {
      6 o# K0 E- r- z0 ~- R1 v% j* L
    46.         if (password.isEmpty()) {
      0 {% r5 N% y' t+ i! K
    47.             System.out.println("必须在config.properties中填写密码号!");
      ) W3 U+ G& j% W9 F
    48.         }
      8 {5 c# P' _) [
    49.         this.password = password;
      - i. [5 g- q  I4 R6 l
    50.     }& d# J" G: w3 d  E
    51.         public static Config getInstance() {- k' S  s  v0 U7 X9 [- E) \
    52.         return ConfigInstance.INSTANCE;) r; n. A- V) L/ l
    53.     }
      ! t- L: N" `/ w0 Y- c
    54. }
    复制代码
    调用小黄鸡接口 SimsimiTools.java:( B/ s7 K) P4 _0 R; G: `+ K( i
    1. public class SimsimiTools {- i. V& n8 F% b# a, u  E
    2.             /**- [  b) `4 p! J" U2 `) d' f4 _
    3.              * 小黄鸡机器人& _6 @0 K% U0 [7 @4 j
    4.              * $ \$ `6 A/ g6 J! o" j
    5.              * @author ghma( H+ V! C# R& [) J
    6.              */  h: l- p. M6 n6 p1 m' T
    7.             public static String getSimsimiContentByNiuren(String params) {
      2 I* R, |5 O- S. M1 ]* t& |  m$ [
    8.                 StringBuffer bufferRes = new StringBuffer();
      / v! H' G% ~; P8 K. f/ B$ w! i* P
    9.                 try {
      5 c0 `- |: O3 o# d% N: f* W) y# I
    10.                     URL realUrl = new URL(
      5 h; l( H! c! g& n4 v' p# q. {
    11.                             "http://www.niurenqushi.com/app/simsimi/ajax.aspx");
      # m+ S. ~( l1 a# }: H
    12.                     HttpURLConnection conn = (HttpURLConnection) realUrl
      1 L! r% J$ g0 h4 j1 ]* r
    13.                             .openConnection();9 U' K& e  z" M8 V$ N: b& `8 q
    14.                     // 连接超时2 u- [: o3 e$ e9 }2 d
    15.                     conn.setConnectTimeout(25000);& @& P$ U: m3 l( \3 l9 s; j- Y
    16.                     // 读取超时 --服务器响应比较慢,增大时间
      5 D, i0 C* S2 x
    17.                     conn.setReadTimeout(25000);$ J9 x/ o) P! i+ y0 O  \7 T
    18.                     HttpURLConnection.setFollowRedirects(true);7 o  N- }! ~  C" [: P* N
    19.                     // 请求方式, R1 L. `7 V2 d( F( F
    20.                     conn.setRequestMethod("POST");# y' b2 i, S6 s9 {# `5 H' H
    21.                     conn.setDoOutput(true);
      " R+ O0 s# K, U2 c! \+ b$ T  K
    22.                     conn.setDoInput(true);
      . M1 a0 D6 J8 s0 @& Y0 Z
    23.                     conn.setRequestProperty("User-Agent",* g! j& n- p( {& ?+ d7 a- l
    24.                             "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0");
      / e( S5 g; K) d) C/ K' C9 ~: H9 h
    25.                     conn.setRequestProperty("Accept", "*/*");
      6 ]! x( t0 S: c5 W
    26.                     conn.setRequestProperty("Referer",
      % l7 t* |% }, \
    27.                             "http://www.niurenqushi.com/app/simsimi/");9 D5 [  w; r2 p! f! H5 A! `1 ?
    28.                     conn.connect();8 M2 w& u& L, F4 ]
    29.                     // 获取URLConnection对象对应的输出流
      / Q+ }0 S! e" C
    30.                     OutputStreamWriter out = new OutputStreamWriter(
      3 k8 [8 z# z9 H' j  u/ A6 d
    31.                             conn.getOutputStream());
        B; K* t* ~0 t5 ]
    32.                     // 发送请求参数  o7 m2 U$ ^' E
    33.                     out.write("txt=" + URLEncoder.encode(params, "UTF-8"));1 f4 z. L* U3 q4 ?7 R9 Q' ?9 `5 l5 B
    34.                     out.flush();
      + ]( ~/ I1 o; P: O2 d9 k, I8 l
    35.                     out.close();
      / y; x  g, [0 F$ g$ ^/ p$ i3 F
    36.                     InputStream in = conn.getInputStream();/ y/ l/ o" K: x# S! \* M
    37.                     BufferedReader read = new BufferedReader(new InputStreamReader(in,
      " S' g9 }. N8 e; I6 f& \
    38.                             "UTF-8"));
      9 G* _1 v5 b/ q' Y; G
    39.                     String valueString = null;
      " l9 z( {) |  n# b8 M1 T
    40.                     while ((valueString = read.readLine()) != null) {
      1 P* r3 l% v8 g* b# r
    41.                         bufferRes.append(valueString);1 q4 {8 J  L6 L: R! h  A  w
    42.                     }
      3 o9 S' u1 l, |4 R/ c' L5 W
    43.                     in.close();
      5 @  o! n& U! n
    44.                     if (conn != null) {$ q% M' N6 x( C0 Y! y
    45.                         // 关闭连接
        f* i% e6 [, s8 r) }  _, A; c* U
    46.                         conn.disconnect();3 }$ D4 b* ]& M# Q+ J
    47.                     }
      8 m9 q) f1 C6 ?2 d+ a# g6 b& l- p% u
    48.                 } catch (Exception e) {; `; H' G. ~: U2 X
    49.                     //System.out.println("小黄鸡接口调用出错!" + e.getMessage());4 j0 ~) x7 f, `6 y" z
    50.                 }
      ! w- ?3 t+ E' F* a" p

    51. 5 Q: a2 E3 X& p" p$ [- z" K' l
    52.                 if (bufferRes.toString().equals("干嘛")) {0 e; a' {" j5 p0 }2 {% X) F
    53.                    // return XiaoDouMachine.getXiaoDouMsg(params);
      1 t3 @( z1 O6 [  @& ?. e0 ]
    54.                 }# D0 d3 R, q2 {
    55.                 String finalRes = removeNews(bufferRes.toString());
      $ A  O, ^& s: O. K
    56.                 //System.out.println("小黄鸡机器人回复:" + finalRes);
      & a/ @7 J- y7 V8 h" Z' s  @/ F' q
    57.                 return finalRes;
      6 {9 ]0 K0 c0 n) O# s+ Z/ g
    58.             }. Y9 L$ ~4 R' W4 D& E* s% z
    59.             /**( o" a6 ~' G% K
    60.              * 屏蔽当前接口中的广告
      , ^& b# X, e8 ^6 E; e( q
    61.              *
      . j8 B; N3 d% R+ x
    62.              * @return
      ) A/ m5 d+ Q% o, l4 t
    63.              */
      2 B' }( u5 i2 K  k
    64.             public static String removeNews(String sendMsgs) {
      & f; D% R$ f9 {$ s4 F2 K
    65.                 // 去除广告
      / f% j: u/ @$ \# [8 n
    66.                 if (sendMsgs.indexOf("simsimi2") != -1) {' T3 o& u: {) ^6 B9 p
    67.                     sendMsgs = "偶是毛小驴,女,还木有男友,欢迎南华学子调戏   O(∩_∩)O";
      4 Z4 L& y* K( O8 u% a# C2 `3 q. a: Z
    68.                 } else if (sendMsgs.indexOf("Database") != -1
      $ a4 A  e) y& Y# m
    69.                         || sendMsgs.indexOf("Failed") != -1) {" Q$ R9 x+ A- e. k: n
    70.                     int random = (int) (Math.random() * 5);+ M7 C& @6 x1 O( s. f  W" K2 `
    71.                     switch (random) {
      6 n/ ~( t5 q1 y$ D1 }  `
    72.                     case 1:. s. m8 I% U* P, H7 ~
    73.                         sendMsgs = "嗯";$ G& F8 Y2 y; J: j1 E
    74.                         break;
      0 S# r5 m2 ?  _6 t
    75.                     case 2:$ V6 {! B1 q/ L3 A
    76.                         sendMsgs = "聊天其它的吧";
      # _5 M7 r' X4 j8 b3 R
    77.                         break;8 }4 D% G2 p0 N9 u  |; Y4 \
    78.                     case 3:
      0 A0 R/ S3 o8 R3 t6 ^) m3 B
    79.                         sendMsgs = "嗯哼";
      ; K7 Y( p4 K0 V0 C/ f
    80.                         break;
      1 ^4 G# d% E9 @1 c" U3 G
    81.                     case 4:
      ! t, Y6 u& l4 w" m3 B
    82.                         sendMsgs = "哎呀";1 {- A4 |; x/ S/ M
    83.                         break;# a$ |1 l+ m% Z  G; i+ t
    84.                     case 5:
      1 x) Q' c% w! K# {) K0 W3 n% C
    85.                         sendMsgs = "额";/ s8 Z4 V8 p, y) N
    86.                         break;
      - ]5 u8 u4 Y$ e8 v
    87.                     default:
      ) O2 ~# C: l& w+ S  q4 U0 i
    88.                         sendMsgs = "嗯";/ V  g7 U% e5 D9 F- Y4 i% p
    89.                         break;( f4 s  L6 A0 J& g$ {. N1 ]5 t- p
    90.                     }( ^1 a; L9 w! C' X( g; D2 P4 E! e5 s
    91.                 } else if (sendMsgs.indexOf("Unauthorized access") != -1) {0 A& h$ O- Y3 R3 v/ x7 p" p
    92.                     sendMsgs = "我怎么听不懂你说的什么意思呀[大哭]。咱们能换个话题吗!";
      5 W$ G. X. s+ Y
    93.                 } else if (sendMsgs.indexOf("你可以教我回答") != -1) {& N+ p7 h4 f0 ~% T# Q
    94.                     sendMsgs = "好吧";
        O7 ~, d" h- g  B( S+ T1 D
    95.                 }
      ' [: A! H& W2 M3 V: p2 E( F
    96.                 // 替换部分内容- {4 l) q$ y/ m2 c  Y7 O! }
    97.                 sendMsgs = sendMsgs.replaceAll("傻逼", "sb");# z" d" d5 l8 l* Q. o
    98.                 sendMsgs = sendMsgs.replaceAll("小九", "毛小驴");+ C6 n4 F6 {0 U
    99.                 sendMsgs = sendMsgs.replaceAll("小豆", "小贱贱");
      ) t" e( C8 `3 w: A  K+ q) Z7 h
    100.                 sendMsgs = sendMsgs4 u" E0 w6 Z8 }7 ]1 j+ H
    101.                         .replaceAll(% r- z, D: s" x0 P  m
    102.                                 "小豆机器人网页版地址:http://www.52itstyle.top QQ个性网http://www.52itstyle.top",
      ! [% T; y2 h8 [
    103.                                 "伦家不懂官人的话了啦~");
      1 Y  h% m: a( V8 [4 r  f$ ~
    104.                 sendMsgs = sendMsgs.replaceAll("小豆", "毛小驴");, t& N# K8 V3 {$ ?7 P. ^( B+ `- c& E
    105.                 sendMsgs = sendMsgs.replaceAll("人家", "伦家");
      * v/ {# M4 x# P" X9 ?8 W1 I
    106.                 sendMsgs = sendMsgs.replaceAll("科帮网http://www.52itstyle.top",
      / s- c5 S  W) f! N9 }3 L$ Z/ U' H% |
    107.                         "伦家不懂官人的话了啦~");
      7 K. q, H4 y1 }2 u. v. c
    108.                 return sendMsgs;
      ! K& ], n. @, a; f3 S
    109.             }
      . X6 J& i/ K( A: n6 S7 g1 v! K
    110. }
    复制代码
    根据城市名字调用天气接口Weather.java:9 X  H4 `+ S5 c5 ^5 ]5 E4 B# C- o. L$ r
    1. public class Weather { " o- K& A. `+ Z9 P3 d& ~# e
    2.     public  static String Weather(String cityName) throws IOException ,NullPointerException{
      ; K) i0 X6 H/ ~4 V# {+ E" B  R4 f
    3.             String Cityid=  getCityId(cityName);
      & t, P4 W+ _  g3 E
    4.         // 连接中央气象台的API
        q- D! m* h7 J8 Z3 f5 ]& O* ?
    5.         URL url = new URL("http://m.weather.com.cn/data/" + Cityid + ".html"); - g' [2 E3 t! ~. J9 v
    6.         System.out.println(url);
      ) Z. ^6 K9 W& O
    7.         URLConnection  connectionData = url.openConnection(); 4 }- d" h/ w$ g
    8.         connectionData.setConnectTimeout(1000); 2 h# r  j4 v/ f9 B  I& `! E
    9.         StringBuilder sb = new StringBuilder();
      & D. ~* K% e0 Q% J) q: j" w
    10.         try { " g" Y4 B# s# t) X& Y8 c) w! n
    11.                 BufferedReader br = new BufferedReader(new InputStreamReader( 0 J" |0 y( X) [  n: w
    12.                     connectionData.getInputStream(), "UTF-8")); * O( q* T9 ?6 w$ m% M
    13.             String line = null;
      % x" |  L' X/ P$ \% p
    14.             while ((line = br.readLine()) != null) 5 V0 {9 ~1 ~9 n% B
    15.                 sb.append(line); " S! x' L  T% V/ s& J; o
    16.         } catch (SocketTimeoutException e) { + c  P9 e" y: Q% b5 E* t# q* U
    17.             System.out.println("连接超时");
      ) L* R8 b7 H( N- X$ d) `: v
    18.         } catch (FileNotFoundException e) {
      1 H3 w6 L$ L4 |
    19.             System.out.println("加载文件出错"); " N' U6 ?4 @; ^, D5 P. p
    20.         }
      9 i- G* D. C: u
    21.          String datas = sb.toString();   + O+ s$ V" y; S9 {* d/ Q- l$ O
    22.          JSONObject jsonData = JSONObject.fromObject(datas); : ^9 C9 ?8 P- Q1 g! Y  }5 J
    23.          JSONObject info = jsonData.getJSONObject("weatherinfo");
      ) D1 @" J: v2 L5 Q6 X) J1 R# m
    24.         //得到1到6天的天气情况
      % z$ E" k5 P' @8 w; F& M
    25.         List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();' I: t7 Q: W9 ]# J8 O1 I
    26.         sb = new StringBuilder();
      / X: B% A( J' @4 c
    27.         for(int i=1;i<=3;i++){
      ! d6 l/ S% c' y* ?# S
    28.             //得到未来6天的日期
      ) W1 x) {% @2 z$ n0 {
    29.             Calendar cal = Calendar.getInstance();
      8 E* W" P' V3 ]) L2 e& W' a3 G6 q, k
    30.             cal.add(Calendar.DAY_OF_YEAR, i-1);
      & x4 R  c0 T) A+ Z# k* F. z
    31.             Date date = cal.getTime();2 ~9 g: A: K4 W) |# s* i
    32.             SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日");. _. X& I/ R) F4 R, d2 P1 D
    33.             Map<String,Object> map = new HashMap<String, Object>();
      2 ~$ m8 o8 j- C+ j3 a, I; H
    34.             map.put("city", info.getString("city").toString());//城市0 k* y$ D6 b1 T* D+ F
    35.             map.put("date_y", sf.format(date));//日期" I% B3 H: }$ b# m/ _6 e
    36.             map.put("week", getWeek(cal.get(Calendar.DAY_OF_WEEK)));//星期
      ' {2 j0 p% d9 _0 \7 E
    37.             map.put("fchh", info.getString("fchh").toString());//发布时间. O* {* c# F9 X4 u  u  j
    38.             map.put("weather", info.getString("weather"+i).toString());//天气9 O$ @- r/ ^7 |( m! @5 E1 o( {
    39.             map.put("temp", info.getString("temp"+i).toString());//温度
        K) o& p  x. N2 p" u  v  D2 X. L' P
    40.             map.put("wind", info.getString("wind"+i).toString());//风况
      8 m+ w" _9 M2 t) ~
    41.             map.put("fl", info.getString("fl"+i).toString());//风速7 v5 k$ e2 r% z5 a
    42.             map.put("index", info.getString("index").toString());// 今天的穿衣指数
      - {( x) p! F' E
    43.             map.put("index_uv", info.getString("index_uv").toString());// 紫外指数 8 n/ e  ]+ U, Q; e: z- y9 F
    44.             map.put("index_tr", info.getString("index_tr").toString());// 旅游指数 ; o; U) h( }/ ^, e4 S& A6 y
    45.             map.put("index_co", info.getString("index_co").toString());// 舒适指数 * i# p7 a% |2 ~& H' O5 Y
    46.             map.put("index_cl", info.getString("index_cl").toString());// 晨练指数 8 i$ M2 L3 ]/ p; k4 ?  I- Z5 e
    47.             map.put("index_xc", info.getString("index_xc").toString());//洗车指数 " B' v3 V( Q% p" Y5 X1 L, e7 t
    48.             map.put("index_d", info.getString("index_d").toString());//天气详细穿衣指数
        T% Y- R. R2 T$ j+ R% `6 X
    49.             list.add(map);# r5 h: }& l& m: Z$ d) s: J1 T1 z- ]
    50.         }
      4 e$ O1 _$ q( m& n' c5 e( r
    51.         //控制台打印出天气( c  e5 F, s* o6 Z1 w
    52.        for(int j=0;j<list.size();j++){9 q8 R# O# I4 t( i( _1 t
    53.            Map<String,Object> wMap = list.get(j);$ j( d/ K+ j, Z5 m( V. ^
    54.            sb.append(wMap.get("city")+"\t"+wMap.get("date_y")+"\t"+wMap.get("week")+"\t"
      * x" _$ r- y1 Q
    55.                    +wMap.get("weather")+"\t"+wMap.get("temp")+"\t"+wMap.get("index_uv")+"\n");0 G) u! B! Y" z
    56.        }
      7 f& z! ^) p$ g9 q4 {
    57.        return sb.toString();5 [  F, T% J7 A1 a0 l
    58.   
      ! U6 m) o, o  L" X# t
    59.     }
      " o1 Q/ L2 @2 A8 p4 O8 x! a
    60.     private static String  getWeek(int iw){
      . E6 |2 O& j1 b5 x4 H5 b9 N
    61.         String weekStr = "";
      0 @/ a' c& p; q
    62.         switch (iw) {
      : M* D1 P# ^/ c3 R+ Z3 {2 d
    63.         case 1:weekStr = "星期天";break;! W9 a+ M5 U; V" t1 J8 H
    64.         case 2:weekStr = "星期一";break;
      ( B* v7 X7 Z( d
    65.         case 3:weekStr = "星期二";break;* U8 d: v( r2 w7 M! R) a
    66.         case 4:weekStr = "星期三";break;: l# f# @1 x# \8 z7 w5 W
    67.         case 5:weekStr = "星期四";break;6 G& |8 S; A9 R2 V6 W
    68.         case 6:weekStr = "星期五";break;
      6 w8 h2 \& V" ]- V% `
    69.         case 7:weekStr = "星期六";break;
      ( C: b# E2 @/ w2 Q/ Z% D4 G4 K
    70.         default:
      5 ~7 [) P$ Y% M; @1 w( l7 M2 V
    71.             break;+ @3 q3 ~: u: ]  [' a& f6 M
    72.         }- o0 v, x: C, n
    73.         return weekStr;* V; F6 C2 R# s' D! V/ |4 h2 a" c
    74.     }
      9 K+ ?2 n  m1 l* z
    75.     private static String  getCityId(String cityName){
      ) T2 |/ c4 ^0 R, ^  h( i
    76.         Map<String,String> map = new HashMap<String, String>();
      6 d! d2 F% M0 W; R/ l& R: c3 j9 i
    77.         map.put("北京","101010100");map.put("上海","101020100");map.put("天津","101030100");map.put("重庆","101040100");map.put("香港","101320101");map.put("澳门","101330101");map.put("哈尔滨","101050101");map.put("齐齐哈尔","101050201");map.put("牡丹江","101050301");map.put("大庆","101050901");map.put("伊春","101050801");map.put("双鸭山","101051301");map.put("鹤岗","101051201");map.put("鸡西","101051101");map.put("佳木斯","101050401");map.put("七台河","101051002");map.put("黑河","101050601");map.put("绥化","101050501");map.put("大兴安岭","101050701");map.put("长春","101060101");map.put("延吉","101060301");map.put("吉林","101060201");map.put("白山","101060901");map.put("白城","101060601");map.put("四平","101060401");map.put("松原","101060801");map.put("辽源","101060701");map.put("大安","101060603");map.put("通化","101060501");map.put("沈阳","101070101");map.put("大连","101070201");map.put("葫芦岛","101071401");map.put("盘锦","101071301");map.put("本溪","101070501");map.put("抚顺","101070401");map.put("铁岭","101071101");map.put("辽阳","101071001");map.put("营口","101070801");map.put("阜新","101070901");map.put("朝阳","101071201");map.put("锦州","101070701");map.put("丹东","101070601");map.put("鞍山","101070301");map.put("呼和浩特","101080101");map.put("呼伦贝尔","101081000");map.put("锡林浩特","101080901");map.put("包头","101080201");map.put("赤峰","101080601");map.put("海拉尔","101081001");map.put("乌海","101080301");map.put("鄂尔多斯","101080701");map.put("通辽","101080501");map.put("石家庄","101090101");map.put("唐山","101090501");map.put("张家口","101090301");map.put("廊坊","101090601");map.put("邢台","101090901");map.put("邯郸","101091001");map.put("沧州","101090701");map.put("衡水","101090801");map.put("承德","101090402");map.put("保定","101090201");map.put("秦皇岛","101091101");map.put("郑州","101180101");map.put("开封","101180801");map.put("洛阳","101180901");map.put("平顶山","101180501");
      # h+ q* \  s" {& G, T" L
    78.         map.put("焦作","101181101");map.put("鹤壁","101181201");map.put("新乡","101180301");map.put("安阳","101180201");map.put("濮阳","101181301");map.put("许昌","101180401");map.put("漯河","101181501");map.put("三门峡","101181701");map.put("南阳","101180701");map.put("商丘","101181001");map.put("信阳","101180601");map.put("周口","101181401");map.put("驻马店","101181601");map.put("太原","101100101");map.put("阳泉","101100301");map.put("晋城","101100601");map.put("晋中","101100401");map.put("临汾","101100701");map.put("运城","101100801");map.put("长治","101100501");map.put("朔州","101100901");map.put("忻州","101101001");map.put("大同","101100201");map.put("吕梁","101101101");map.put("西安","101110101");map.put("韩城","101110510");map.put("安康","101110701");map.put("汉中","101110801");map.put("宝鸡","101110901");map.put("咸阳","101110200");map.put("榆林","101110401");map.put("渭南","101110501");map.put("商洛","101110601");map.put("铜川","101111001");map.put("延安","101110300");map.put("银川","101170101");map.put("固原","101170401");map.put("中卫","101170501");map.put("石嘴山","101170201");map.put("吴忠","101170301");map.put("兰州","101160101");map.put("白银","101161301");map.put("庆阳","101160401");map.put("酒泉","101160801");map.put("天水","101160901");map.put("武威","101160501");map.put("张掖","101160701");map.put("甘南","101050204");map.put("临夏","101161101");map.put("平凉","101160301");map.put("定西","101160201");map.put("金昌","101160601");map.put("西宁","101150101");map.put("海北","101150801");map.put("海西","101150701");map.put("黄南","101150301");map.put("果洛","101150501");map.put("玉树","101150601");map.put("海东","101150201");map.put("海南","101150401");map.put("武汉","101200101");map.put("宜昌","101200901");map.put("黄冈","101200501");map.put("恩施","101201001");map.put("荆州","101200801");map.put("神农架","101201201");map.put("十堰","101201101");map.put("咸宁","101200701");map.put("襄阳","101200201");map.put("孝感","101200401");map.put("随州","101201301");map.put("黄石","101200601");
      + r# P: x( d$ Q) F. F
    79.         map.put("荆门","101201401");map.put("鄂州","101200301");map.put("长沙","101250101");map.put("邵阳","101250901");map.put("常德","101250601");map.put("郴州","101250501");map.put("吉首","101251501");map.put("株洲","101250301");map.put("娄底","101250801");map.put("湘潭","101250201");map.put("益阳","101250701");map.put("永州","101251401");map.put("岳阳","101251001");map.put("衡阳","101250401");map.put("怀化","101251201");map.put("韶山","101250202");map.put("张家界","101251101");map.put("杭州","101210101");map.put("湖州","101210201");map.put("金华","101210901");map.put("宁波","101210401");map.put("丽水","101210801");map.put("绍兴","101210501");map.put("衢州","101211001");map.put("嘉兴","101210301");map.put("台州","101210601");map.put("舟山","101211101");map.put("温州","101210701");map.put("南昌","101240101");map.put("萍乡","101240901");map.put("九江","101240201");map.put("上饶","101240301");map.put("抚州","101240401");map.put("吉安","101240601");map.put("鹰潭","101241101");map.put("宜春","101240501");map.put("新余","101241001");map.put("景德镇","101240801");map.put("赣州","101240701");map.put("福州","101230101");map.put("厦门","101230201");map.put("龙岩","101230701");map.put("南平","101230901");map.put("宁德","101230301");map.put("莆田","101230401");map.put("泉州","101230501");map.put("三明","101230801");map.put("漳州","101230601");map.put("贵阳","101260101");map.put("安顺","101260301");map.put("赤水","101260208");map.put("遵义","101260201");map.put("铜仁","101260601");map.put("六盘水","101260801");map.put("毕节","101260701");map.put("凯里","101260501");map.put("都匀","101260401");map.put("成都","101270101");map.put("泸州","101271001");map.put("内江","101271201");map.put("凉山","101271601");map.put("阿坝","101271901");map.put("巴中","101270901");map.put("广元","101272101");map.put("乐山","101271401");map.put("绵阳","101270401");map.put("德阳","101272001");map.put("攀枝花","101270201");map.put("雅安","101271701");map.put("宜宾","101271101");map.put("自贡","101270301");map.put("甘孜州","101271801");map.put("达州","101270601");map.put("资阳","101271301");
      % `& Y, [2 v: p2 E$ ]( {( q
    80.         map.put("广安","101270801");map.put("遂宁","101270701");map.put("眉山","101271501");map.put("南充","101270501");0 h' y* ~5 g" J) c' J
    81.         map.put("广州","101280101");map.put("深圳","101280601");map.put("潮州","101281501");map.put("韶关","101280201");- \4 t4 g8 b+ ]  m1 l
    82.         map.put("湛江","101281001");map.put("惠州","101280301");map.put("清远","101281301");map.put("东莞","101281601");9 G) w: `, j6 f3 N9 D' ^. \% D$ G
    83.         map.put("江门","101281101");map.put("茂名","101282001");map.put("肇庆","101280901");map.put("汕尾","101282101");
      & O) D( E( T* J" F
    84.         map.put("河源","101281201");map.put("揭阳","101281901");map.put("梅州","101280401");map.put("中山","101281701");8 b. |# j+ M" m  @( ~: {- \
    85.         map.put("德庆","101280905");map.put("阳江","101281801");map.put("云浮","101281401");map.put("珠海","101280701");4 v( ~' r7 l! M5 o% }
    86.         map.put("汕头","101280501");map.put("佛山","101280800");map.put("南宁","101300101");map.put("桂林","101300501");
      , m! p" `- f1 q2 y0 i$ f
    87.         map.put("阳朔","101300510");map.put("柳州","101300301");map.put("梧州","101300601");map.put("玉林","101300901");  h/ R4 C; ?& o
    88.         map.put("桂平","101300802");map.put("贺州","101300701");map.put("钦州","101301101");map.put("贵港","101300801");
      5 B! t( |" t1 [1 Q5 a: M) K
    89.         map.put("防城港","101301401");map.put("百色","101301001");map.put("北海","101301301");map.put("河池","101301201");
      + w1 D; m$ h. m
    90.         map.put("来宾","101300401");map.put("崇左","101300201");map.put("昆明","101290101");map.put("保山","101290501");
      8 n$ z7 ~' K8 g: M8 i( v
    91.         map.put("楚雄","101290801");map.put("德宏","101291501");map.put("红河","101290301");map.put("临沧","101291101");
      6 a2 j; ]0 N5 J5 G5 w# m; ?) z
    92.         map.put("怒江","101291201");map.put("曲靖","101290401");map.put("思茅","101290901");
      % Q! T* L1 w0 Q+ r
    93.         map.put("文山","101290601");map.put("玉溪","101290701");map.put("昭通","101291001");# W/ ?# R( ?) [5 s$ u4 S
    94.         map.put("丽江","101291401");map.put("大理","101290201");map.put("海口","101310101");$ p* G1 F* a7 {# ^4 ~
    95.         map.put("三亚","101310201");map.put("儋州","101310205");map.put("琼山","101310102");map.put("通什","101310222");
      . f6 o3 z1 _' c3 \: C9 T
    96.         map.put("文昌","101310212");map.put("乌鲁木齐","101130101");map.put("阿勒泰","101131401");map.put("阿克苏","101130801");
      + b! U: j" h: n. u
    97.         map.put("昌吉","101130401");map.put("哈密","101131201");map.put("和田","101131301");map.put("喀什","101130901");" Z6 T" R/ Q8 K+ E. s
    98.         map.put("克拉玛依","101130201");map.put("石河子","101130301");map.put("塔城","101131101");map.put("库尔勒","101130601");& a1 {+ B" d3 L. w  H+ Y5 y
    99.         map.put("吐鲁番","101130501");map.put("伊宁","101131001");map.put("拉萨","101140101");map.put("阿里","101140701");
      # p- f4 B4 P" z& p. i
    100.         map.put("昌都","101140501");map.put("那曲","101140601");map.put("日喀则","101140201");map.put("山南","101140301");
      9 t7 I" n# S) h' _
    101.         map.put("林芝","101140401");map.put("台北","101340102");map.put("高雄","101340201");map.put("南京","101190101");" W: K7 t, y' G
    102.         map.put("溧水","101190102");map.put("高淳","101190103");map.put("江宁","101190104");map.put("六合","101190105");
      % F, r" e  n! q
    103.         map.put("江浦","101190106");map.put("无锡","101190201");map.put("江阴","101190202");map.put("宜兴","101190203");
      1 O$ E( ]+ c+ g5 `* k7 ^
    104.         map.put("锡山","101190204");map.put("徐州","101190801");map.put("铜山","101190802");map.put("丰县","101190803");
      , q, T+ O7 u+ ]2 |* U( c
    105.         map.put("沛县","101190804");map.put("邳州","101190805");map.put("睢宁","101190806");map.put("新沂","101190807");
      ) N4 U7 t# I9 W( n9 V, U
    106.         map.put("常州","101191101");map.put("溧阳","101191102");map.put("金坛","101191103");map.put("武进","101191104");
      3 I: s! F# d( C. f) T; d
    107.         map.put("苏州","101190401");map.put("常熟","101190402");map.put("张家港","101190403");map.put("昆山","101190404");: p. ^3 e/ \. U
    108.         map.put("吴中","101190405");map.put("吴江","101190407");map.put("太仓","101190408");map.put("南通","101190501");
      $ q, L6 T3 `% T, n! K
    109.         map.put("海安","101190502");map.put("如皋","101190503");map.put("如东","101190504");map.put("启东","101190507");
      6 J7 x  n0 F/ t) h% w3 K& u) J
    110.         map.put("海门","101190508");map.put("通州","101190509");map.put("连云港","101191001");map.put("东海","101191002");
      : F" U! N/ G6 k
    111.         map.put("赣榆","101191003");map.put("灌云","101191004");map.put("灌南","101191005");map.put("淮安","101190901");
      4 k' n8 ]3 m6 A5 o
    112.         map.put("金湖","101190902");map.put("盱眙","101190903");map.put("洪泽","101190904");map.put("涟水","101190905");
      5 g' O5 ?7 _+ d9 r$ t
    113.         map.put("淮阴区","101190906");map.put("淮阴","101190907");map.put("淮安区","101190908");map.put("盐城","101190701");map.put("响水","101190702");map.put("滨海","101190703");map.put("阜宁","101190704");map.put("射阳","101190705");map.put("建湖","101190706");map.put("东台","101190707");map.put("大丰","101190708");map.put("盐都","101190709");map.put("扬州","101190601");map.put("宝应","101190602");map.put("仪征","101190603");map.put("高邮","101190604");map.put("江都","101190605");map.put("邗江","101190606");map.put("镇江","101190301");map.put("丹阳","101190302");map.put("扬中","101190303");map.put("句容","101190304");map.put("丹徒","101190305");map.put("泰州","101191201");map.put("兴化","101191202");map.put("泰兴","101191203");map.put("姜堰","101191204");map.put("靖江","101191205");map.put("宿迁","101191301");map.put("沭阳","101191301");map.put("泗阳","101191301");map.put("泗洪","101191301");map.put("宿豫","101191301");map.put("合肥","101220101");map.put("长丰","101220101");map.put("肥东","101220101");map.put("肥西","101220101");map.put("芜湖","101220301");map.put("繁昌","101220302");map.put("南陵","101220304");map.put("芜湖县","101220303");
      . N3 q4 t6 _  J1 j% P% `
    114.         map.put("蚌埠","101220201");map.put("怀远","101220202");map.put("固镇","101220203");map.put("五河","101220204");map.put("淮南","101220401");map.put("凤台","101220402");map.put("潘集","101220403");map.put("马鞍山","101220501");map.put("当涂","101220502");map.put("淮北","101221201");map.put("濉溪","101221201");map.put("铜陵","101221301");map.put("安庆","101220601");map.put("枞阳","101220602");map.put("太湖","101220603");map.put("潜山","101220604");map.put("怀宁","101220605");map.put("宿松","101220606");map.put("望江","101220607");map.put("岳西","101220608");map.put("桐城","101220609");map.put("黄山","101221001");map.put("黄山区","101221002");map.put("屯溪","101221003");map.put("祁门","101221004");map.put("黟县","101221005");map.put("歙县","101221006");map.put("休宁","101221007");map.put("黄山风景区","101221008");map.put("阜阳","101220801");map.put("阜南","101220802");map.put("颍上","101220803");map.put("临泉","101220804");map.put("界首","101220805");map.put("太和","101220806");map.put("宿州","101220701");map.put("砀山","101220702");map.put("灵璧","101220703");map.put("泗县","101220704");map.put("萧县","101220705");map.put("滁州","101221101");map.put("凤阳","101221102");map.put("明光","101221103");map.put("定远","101221104");map.put("全椒","101221105");map.put("来安","101221106");map.put("天长","101221107");map.put("六安","101221501");map.put("寿县","101221503");map.put("霍邱","101221502");map.put("金寨","101221505");map.put("霍山","101221506");map.put("舒城","101221507");map.put("宣城","101221401");map.put("泾县","101221401");map.put("旌德","101221401");map.put("宁国","101221401");map.put("绩溪","101221401");map.put("广德","101221401");map.put("郎溪","101221401");map.put("池州","101221701");map.put("东至","101221702");map.put("青阳","101221703");map.put("九华山","101221704");map.put("石台","101221705");map.put("亳州","101220901");map.put("涡阳","101220902");map.put("利辛","101220903");map.put("蒙城","101220904");map.put("巢湖","101221601");map.put("庐江","101221602");map.put("无为","101221603");map.put("含山","101221604");map.put("和县","101221605");map.put("济南","101120101");map.put("长清","101120102");map.put("商河","101120103");map.put("章丘","101120104");map.put("平阴","101120105");map.put("济阳","101120106");map.put("青岛","101120201");map.put("崂山","101120202");7 c' U4 }. f6 R
    115.         map.put("即墨","101120204");map.put("胶州","101120205");map.put("胶南","101120206");map.put("莱西","101120207");map.put("平度","101120208");map.put("淄博","101120301");map.put("淄川","101120302");map.put("博山","101120303");map.put("高清","101120304");map.put("周村","101120305");map.put("沂源","101120306");map.put("桓台","101120307");map.put("临淄","101120308");map.put("枣庄","101121401");map.put("薛城","101121402");map.put("峄城","101121403");map.put("台儿庄","101121404");map.put("滕州","101121405");map.put("东营","101121201");map.put("河口","101121202");map.put("垦利","101121203");map.put("利津","101121204");map.put("广饶","101121205");map.put("烟台","101120501");map.put("莱州","101120502");map.put("长岛","101120503");map.put("蓬莱","101120504");map.put("龙口","101120505");map.put("招远","101120506");map.put("栖霞","101120507");map.put("福山","101120508");map.put("牟平","101120509");map.put("莱阳","101120510");map.put("海阳","101120511");map.put("潍坊","101120601");map.put("青州","101120602");
      ! |2 D# ^( P" `' t
    116.         map.put("寿光","101120603");map.put("临朐","101120604");map.put("昌乐","101120605");map.put("昌邑","101120606");map.put("安丘","101120607");map.put("高密","101120608");map.put("诸城","101120609");map.put("济宁","101120701");map.put("嘉祥","101120702");map.put("微山","101120703");map.put("鱼台","101120704");map.put("兖州","101120705");map.put("金乡","101120706");map.put("汶上","101120707");map.put("泗水","101120708");map.put("梁山","101120709");map.put("曲阜","101120710");map.put("邹城","101120711");map.put("泰安","101120801");map.put("新泰","101120802");map.put("肥城","101120804");map.put("东平","101120805");map.put("宁阳","101120806");map.put("威海","101121301");map.put("文登","101121302");map.put("荣成","101121303");map.put("乳山","101121304");map.put("成山头","101121305");map.put("石岛","101121306");map.put("日照","101121501");map.put("五莲","101121502");map.put("莒县","101121503");map.put("莱芜","101121601");map.put("临沂","101120901");map.put("莒南","101120902");map.put("沂南","101120903");map.put("苍山","101120904");map.put("临沭","101120905");
      7 @5 |) e) V4 ^5 i$ r# U) T
    117.         map.put("郯城","101120906");map.put("蒙阴","101120907");map.put("平邑","101120908");map.put("费县","101120909");map.put("沂水","101120910");6 \- O/ z$ K1 V# z: c
    118.         map.put("德州","101120401");map.put("武城","101120402");map.put("临邑","101120403");map.put("陵县","101120404");map.put("齐河","101120405");map.put("乐陵","101120406");map.put("庆云","101120407");map.put("平原","101120408");map.put("宁津","101120409");map.put("夏津","101120410");map.put("禹城","101120411");map.put("聊城","101121701");map.put("冠县","101121702");map.put("阳谷","101121703");map.put("高唐","101121704");map.put("茌平","101121705");map.put("东阿","101121706");map.put("临清","101121707");map.put("莘县","101121709");map.put("滨州","101121101");map.put("博兴","101121102");map.put("无棣","101121103");map.put("阳信","101121104");map.put("惠民","101121105");map.put("沾化","101121106");map.put("邹平","101121107");map.put("菏泽","101121001");map.put("鄄城","101121002");map.put("郓城","101121003");map.put("东明","101121004");map.put("定陶","101121005");map.put("巨野","101121006");map.put("曹县","101121007");map.put("成武","101121008");map.put("单县","101121009");
      6 t8 H- f* T* s# t
    119.         System.out.println(cityName);5 {9 m8 H  ~' C$ N& Y
    120.         return map.get(cityName.trim());7 c/ d: C, ]; N/ w+ O# Q: ]) Q
    121.     }
      $ h( _9 n, b: F! z% n
    122. //    public static void main(String[] args) { ! F' I" Q4 Y3 `  @+ B$ L
    123. //        try {
      # x1 i; f1 p6 o$ b6 U
    124. //                //System.out.println(getCityId("胶州"));, W/ g5 @7 f# g9 P/ X9 b% C1 w
    125. //                Weather.Weather("上海");
      1 z; q4 [7 l# {2 @4 @+ G2 ^
    126. //        } catch (Exception e) {
      0 I4 z* j0 g5 ?7 J2 P% B9 V6 j
    127. //            e.printStackTrace(); * e& j0 ~. M. B4 Z, Y; |+ q
    128. //        } - F" O) u, c3 o% x8 D$ O7 _0 B
    129. //    } 1 Z' L9 q" u7 n$ L$ s( U
    130. }
    复制代码
    ( g! c) M9 M1 m: v1 z# B4 }

    1 H7 d4 g3 R! ?: m

    科帮网 1、本主题所有言论和图片纯属会员个人意见,与本社区立场无关
    2、本站所有主题由该帖子作者发表,该帖子作者与科帮网享有帖子相关版权
    3、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和科帮网的同意
    4、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任
    5、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
    6、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
    7、科帮网管理员和版主有权不事先通知发贴者而删除本文


    JAVA爱好者①群:JAVA爱好者① JAVA爱好者②群:JAVA爱好者② JAVA爱好者③ : JAVA爱好者③

    红红火火恍恍惚惚

    10

    主题

    5

    听众

    1108

    金钱

    五袋长老

    该用户从未签到

    90后

    沙发
    发表于 2015-12-31 10:20:52 |只看该作者
    WebQQClientStart  是什么
    回复

    使用道具 举报

    1

    主题

    3

    听众

    341

    金钱

    四袋长老

    该用户从未签到

    板凳
    发表于 2016-03-17 22:07:50 |只看该作者
    学习一下。谢谢
    回复

    使用道具 举报

    woniu 实名认证   

    2

    主题

    0

    听众

    330

    金钱

    四袋长老

    该用户从未签到

    地板
    发表于 2016-04-12 11:39:40 |只看该作者
    这个项目太棒勒!下下来学习下!
    回复

    使用道具 举报

    28

    主题

    1

    听众

    432

    金钱

    四袋长老

    该用户从未签到

    5#
    发表于 2016-04-19 16:50:07 |只看该作者
    学习到了很多类和方法的调用谢谢了!
    回复

    使用道具 举报

    5

    主题

    0

    听众

    316

    金钱

    四袋长老

    该用户从未签到

    6#
    发表于 2017-08-14 08:41:04 |只看该作者
    不错不错不错,学习一下
    回复

    使用道具 举报

    快速回复
    您需要登录后才可以回帖 登录 | 立即注册

       

    关闭

    站长推荐上一条 /1 下一条

    发布主题 快速回复 返回列表 联系我们 官方QQ群 科帮网手机客户端
    快速回复 返回顶部 返回列表