java去哪下微信.怎樣利用UC瀏覽器下

java去哪下微信.怎樣利用UC瀏覽器下

有個S40 六版的微信,java 平臺的,不知道你能不能用:http://down1.app.uc.cn/pack/2013/05/31/AshaWeChatV10Beta62C0.jar

如何使用微信sdk java版

1.首先我們新建一個Java開發(fā)包WeiXinSDK2.包路徑:com.ansitech.weixin.sdk測試的前提條件:假如我的公眾賬號微信號為:vzhanqun 我的服務(wù)器地址為:http://www.vzhanqun.com/下面我們需要新建一個URL的請求地址我們新建一個Servlet來驗證URL的真實性,具體接口參考http://mp.weixin.qq.com/wiki/index.php?title=接入指南3.新建com.ansitech.weixin.sdk.WeixinUrlFilter.java這里我們主要是獲取微信服務(wù)器法師的驗證信息,具體驗證代碼如下[java] view plain copy print?package com.ansitech.weixin.sdk; import com.ansitech.weixin.sdk.util.SHA1; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class WeixinUrlFilter implements Filter { //這個Token是給微信開發(fā)者接入時填的 //可以是任意英文字母或數(shù)字,長度為3-32字符 private static String Token = \”vzhanqun1234567890\”; @Override public void init(FilterConfig config) throws ServletException { System.out.println(\”WeixinUrlFilter啟動成功!\”); } @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; //微信服務(wù)器將發(fā)送GET請求到填寫的URL上,這里需要判定是否為GET請求 boolean isGet = request.getMethod().toLowerCase().equals(\”get\”); System.out.println(\”獲得微信請求:\” + request百科.getMethod() + \” 方式\”); if (isGet) { //驗證URL真實性 String signature = request.getParameter(\”signature\”);// 微信加密簽名 String timestamp = request.getParameter(\”timestamp\”);// 時間戳 String nonce = request.getParameter(\”nonce\”);// 隨機(jī)數(shù) String echostr = request.getParameter(\”echostr\”);//隨機(jī)字符串 List<String> params = new ArrayList<String>(); params.add(Token); params.add(timestamp); params.add(nonce); //1. 將token、timestamp、nonce三個參數(shù)進(jìn)行字典序排序 Collections.sort(params, new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }); //2. 將三個參數(shù)字符串拼接成一個字符串進(jìn)行sha1加密 String temp = SHA1.encode(params.get(0) + params.get(1) + params.get(2)); if (temp.equals(signature)) { response.getWriter().write(echostr); } } else { //處理接收消息 } } @Override public void destroy() { } } 好了,不過這里有個SHA1算法,我這里也把SHA1算法的源碼給貼出來吧!4.新建com.ansitech.weixin.sdk.util.SHA1.java[java] view plain copy print?/* * 微信公眾平臺(JAVA) SDK * * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved. * http://www.ansitech.com/weixin/sdk/ * * Licensed under the Apache License, Version 2.0 (the \”License\”); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an \”AS IS\” BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.ansitech.weixin.sdk.util; import java.security.MessageDigest; /** * <p>Title: SHA1算法</p> * * @author qsyang<yangqisheng274@163.com> */ public final class SHA1 { private static final char[] HEX_DIGITS = {\’0\’, \’1\’, \’2\’, \’3\’, \’4\’, \’5\’, \’6\’, \’7\’, \’8\’, \’9\’, \’a\’, \’b\’, \’c\’, \’d\’, \’e\’, \’f\’}; /** * Takes the raw bytes from the digest and formats them correct. * * @param bytes the raw bytes from the digest. * @return the formatted bytes. */ private static String getFormattedText(byte[] bytes) { int len = bytes.length; StringBuilder buf = new StringBuilder(len * 2); // 把密文轉(zhuǎn)換成十六進(jìn)制的字符串形式 for (int j = 0; j < len; j++) { buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]); buf.append(HEX_DIGITS[bytes[j] & 0x0f]); } return buf.toString(); } public static String encode(String str) { if (str == null) { return null; } try { MessageDigest messageDigest = MessageDigest.getInstance(\”SHA1\”); messageDigest.update(str.getBytes()); return getFormattedText(messageDigest.digest()); } catch (Exception e) { throw new RuntimeException(e); } } } 5.把這個Servlet配置到web.xml中[html] view plain copy print?<filter> <description>微信消息接入接口</description> <filter-name>WeixinUrlFilter</filter-name> <filter-class>com.ansitech.weixin.sdk.WeixinUrlFilter</filter-class> </filter> <filter-mapping> <filter-name>WeixinUrlFilter</filter-name> <url-pattern>/api/vzhanqun</url-pattern> </filter-mapping> 好了,接入的開發(fā)代碼已經(jīng)完成。6.下面就把地址URL和密鑰Token填入到微信申請成為開發(fā)者模式中吧。

JAVA手機(jī)能用微信嗎?

JAVA手機(jī)不能使用微信。微信只支持symbian和android等智能系統(tǒng)手機(jī)。

微信支持多種語言,支持Wi-Fi無線局域網(wǎng)、2G,3G和4G移動數(shù)據(jù)**,iOS版,Android版、Windows Phone版、Blackberry版、諾基亞S40版、S60V3和S60V5版。

微信的**版本:5.2.1(Android)、5.2.0.17(iOS)、4.2(Symbian)、5.1.0.0(Windows Phone 8)、1.5(諾基亞S40)、3.0(BlackBerry)、2.0(BlackBerry 10)。

如何用java開發(fā)微信

說明:本次的教程主要是對微信公眾平臺開發(fā)者模式的講解,**上很多類似文章,但很多都讓初學(xué)微信開發(fā)的人一頭霧水,所以總結(jié)自己的微信開發(fā)經(jīng)驗,將微信開發(fā)的整個過程系統(tǒng)的列出,并對主要代碼進(jìn)行講解分析,讓初學(xué)者盡快上手。在閱讀本文之前,應(yīng)對微信公眾平臺的**開發(fā)文檔有所了解,知道接收和發(fā)送的都是xml格式的數(shù)據(jù)。

另外,在做內(nèi)容回復(fù)時用到了圖靈機(jī)器人的api接口,這是一個自然語言解析的開放平臺,可以幫我們解決整個微信開發(fā)過程中最困難的問題,此處不多講,下面會有其詳細(xì)的調(diào)用方式。

1.1 在登錄微信**平臺之后,開啟開發(fā)者模式,此時需要我們填寫url和token,所謂url就是我們自己服務(wù)器的接口,用WechatServlet.java來實現(xiàn),相關(guān)解釋已經(jīng)在注釋中說明,代碼如下:

[java]?view plain?copy

package?demo.servlet;

import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.InputStreamReader;
import?java.io.OutputStream;

import?javax.servlet.ServletException;
import?javax.servlet.http.HttpServlet;
import?javax.servlet.http.HttpServletRequest;
import?javax.servlet.http.HttpServletResponse;

import?demo.process.WechatProcess;
/**
*?微信服務(wù)端收發(fā)消息接口
*
*?@author?pamchen-1
*
*/
public?class?WechatServlet?extends?HttpServlet?{

/**
*?The?doGet?method?of?the?servlet.?<br>
*
*?This?method?is?called?when?a?form?has?its?tag?value?method?equals?to?get.
*
*?@param?request
*?the?request?send?by?the?client?to?the?server
*?@param?response
*?the?response?send?by?the?server?to?the?client
*?@throws?ServletException
*?if?an?error?occurred
*?@throws?IOException
*?if?an?error?occurred
*/
public?void?doGet(HttpServletRequest?request,?HttpServletResponse?response)
throws?ServletException,?IOException?{
request.setCharacterEncoding(\”UTF-8\”);
response.setCharacterEncoding(\”UTF-8\”);

/**?讀取接收到的xml消息?*/
StringBuffer?**?=?new?StringBuffer();
InputStream?is?=?request.getInputStream();
InputStreamReader?isr?=?new?InputStreamReader(is,?\”UTF-8\”);
BufferedReader?br?=?new?BufferedReader(isr);
String?s?=?\”\”;
while?((s?=?br.readLine())?!=?null)?{
**.append(s);
}
String?xml?=?**.toString();?//次即為接收到微信端發(fā)送過來的xml數(shù)據(jù)

String?result?=?\”\”;
/**?判斷是否是微信接入激活驗證,只有首次接入驗證時才會收到echostr參數(shù),此時需要把它直接返回?*/
String?echostr?=?request.getParameter(\”echostr\”);
if?(echostr?!=?null?&&?echostr.length()?>?1)?{
result?=?echostr;
}?else?{
//正常的微信處理流程
result?=?new?WechatProcess().processWechatMag(xml);
}

try?{
OutputStream?os?=?response.getOutputStream();
os.write(result.getBytes(\”UTF-8\”));
os.flush();
os.close();
}?catch?(Exception?e)?{
e.printStackTrace();
}
}

/**
*?The?doPost?method?of?the?servlet.?<br>
*
*?This?method?is?called?when?a?form?has?its?tag?value?method?equals?to
*?post.
*
*?@param?request
*?the?request?send?by?the?client?to?the?server
*?@param?response
*?the?response?send?by?the?server?to?the?client
*?@throws?ServletException
*?if?an?error?occurred
*?@throws?IOException
*?if?an?error?occurred
*/
public?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)
throws?ServletException,?IOException?{
doGet(request,?response);
}

}
1.2 相應(yīng)的web.xml配置信息如下,在生成WechatServlet.java的同時,可自動生成web.xml中的配置。前面所提到的url處可以填寫例如:http;//服務(wù)器地址/項目名/wechat.do

[html]?view plain?copy
<?xml?version=\”1.0\”?encoding=\”UTF-8\”?>
<web-app?version=\”2.5\”
xmlns=\”http://java.sun.com/xml/ns/javaee\”
xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance\”
xsi:schemaLocation=\”http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\”>
<servlet>
<description>This?is?the?description?of?my?J2EE?component</description>
<display-name>This?is?the?display?name?of?my?J2EE?component</display-name>
<servlet-name>WechatServlet</servlet-name>
<servlet-class>demo.servlet.WechatServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>WechatServlet</servlet-name>
<url-pattern>/wechat.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
1.3 通過以上代碼,我們已經(jīng)實現(xiàn)了微信公眾平臺開發(fā)的框架,即開通開發(fā)者模式并成功接入、接收消息和發(fā)送消息這三個步驟。
下面就講解其核心部分——解析接收到的xml數(shù)據(jù),并以文本類消息為例,通過圖靈機(jī)器人api接口實現(xiàn)智能回復(fù)。2.1 首先看一下整體流程處理代碼,包括:xml數(shù)據(jù)處理、調(diào)用圖靈api、封裝返回的xml數(shù)據(jù)。