【请教】要在CRM系统里面实现一个 天气预报功能

zhoupingxiao 2010-10-14 04:09:49
公司要在CRM系统中调用天气预报
用JAVA写的系统
请问高手可以怎么实现???
...全文
126 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoupingxiao 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 dr_lou 的回复:]

给你一个webservice接口吧。

Java code
package weather.receiver.control;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.UR……
[/Quote]MyLogger 在哪里?
zhoupingxiao 2010-10-15
  • 打赏
  • 举报
回复

WebService 还用得不太熟!呵呵
javahailangL 2010-10-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhoupingxiao 的回复:]
引用 1 楼 attached 的回复:

http://www.google.cn/search?client=pub-9408333546887817&hl=zh-CN&source=hp&q=%E5%A4%A9%E6%B0%94%E9%A2%84%E6%8A%A5&aq=0&oq=%E5%A4%A9%E6%B……
[/Quote]

学习一下

有不懂的地方 好像
kaida_7 2010-10-14
  • 打赏
  • 举报
回复
WebService
dr_lou 2010-10-14
  • 打赏
  • 举报
回复
给你一个webservice接口吧。

package weather.receiver.control;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import weather.logger.MyLogger;

public class WeatherManager {
private static MyLogger logWriter = new MyLogger(WeatherManager.class.getName());

public static String GetWeather(String cityName) {
String w = null;// 公用w

try {
Document doc;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = getSoapInputStream(cityName);
if (is == null) {
return null;
}
doc = db.parse(is);
NodeList nl = doc.getElementsByTagName("string");

StringBuffer sb = new StringBuffer();
for (int count = 0; count < nl.getLength(); count++) {
Node n = nl.item(count);
if (n.getFirstChild().getNodeValue().equals("查询结果为空!")) {
sb = new StringBuffer("#");
break;
}
sb.append(n.getFirstChild().getNodeValue() + "#\n");
}
is.close();

w = sb.toString();

} catch (Exception e) {
logWriter.error(e.fillInStackTrace());
}
return w;
}

private static String getSoapRequest(String city) {
StringBuffer sb = new StringBuffer();
sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+ "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body> <getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">"
+ "<theCityName>" + city
+ "</theCityName> </getWeatherbyCityName>"
+ "</soap:Body></soap:Envelope>");

return sb.toString();
}

private static InputStream getSoapInputStream(String city) throws Exception {
try {
String soap = getSoapRequest(city);
if (soap == null) {
return null;
}
URL url = new URL(
"http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
URLConnection conn = url.openConnection();
conn.setConnectTimeout(1000 * 30);
conn.setReadTimeout(1000 * 60);
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);

conn.setRequestProperty("Content-Length", Integer.toString(soap
.length()));
conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
conn.setRequestProperty("SOAPAction",
"http://WebXml.com.cn/getWeatherbyCityName");

OutputStream os = conn.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os, "utf-8");
osw.write(soap);
osw.flush();
osw.close();

InputStream is = conn.getInputStream();
return is;
} catch (Exception e) {
logWriter.error(e);
return null;
}
}
}
zhoupingxiao 2010-10-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 attached 的回复:]

http://www.google.cn/search?client=pub-9408333546887817&hl=zh-CN&source=hp&q=%E5%A4%A9%E6%B0%94%E9%A2%84%E6%8A%A5&aq=0&oq=%E5%A4%A9%E6%B0%94
直接添加,读取gogle的的天气预报
[/Quote]没弄明白,能说具体点么?
webrobot 2010-10-14
  • 打赏
  • 举报
回复
很好。收藏了
feixiaocaohen 2010-10-14
  • 打赏
  • 举报
回复
同意楼上的,加油,开心每一天
attached 2010-10-14
  • 打赏
  • 举报
回复
http://www.google.cn/search?client=pub-9408333546887817&hl=zh-CN&source=hp&q=%E5%A4%A9%E6%B0%94%E9%A2%84%E6%8A%A5&aq=0&oq=%E5%A4%A9%E6%B0%94
直接添加,读取gogle的的天气预报

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧