首页编程java编程微信用户 java代码是什么意思啊 微信java开发标准是什么

微信用户 java代码是什么意思啊 微信java开发标准是什么

编程之家 2023-10-14 94次浏览

各位老铁们,大家好,今天由我来为大家分享微信用户 java代码是什么意思啊,以及微信java开发标准是什么的相关问题知识,希望对大家有所帮助。如果可以帮助到大家,还望关注收藏下本站,您的支持是我们最大的动力,谢谢大家了哈,下面我们开始吧!

微信用户 java代码是什么意思啊 微信java开发标准是什么

微信定机票的时候 出来一个openid为空是什么意思啊

1openid是公众号的普通用户的一个唯一的标识,只针对当前的公众号有效,只要获得OpenID,就可以相继获得用户的一些信息,如:所在城市、省份、国家、姓别等,应该是没有绑定身份证和手机

OpenID是一个以用户为中心的数字身份识别框架,它具有开放、分散性。OpenID的创建基于这样一个概念:我们可以通过 URI(又叫 URL或网站地址)来认证一个网站的唯一身份,同理,我们也可以通过这种方式来作为用户的身份认证。

扩展资料:

微信用户 java代码是什么意思啊 微信java开发标准是什么

协议扩展

OpenID协议提供了一个基本的认证机制。目前还有基于OpenID的其它可用协议:

Attribute Exchange:OpenID属性交换是一种用于在端点之间交换标识信息OpenID服务扩展。其提供了对标识信息的接收和存储。

微信用户 java代码是什么意思啊 微信java开发标准是什么

Simple Registration:这是OpenID认证协议的扩展,它允许非常轻量级的配置交换。主要用于在终端用户使用web服务注册新帐号时传送八种常用的请求信息。

使用OpenID4Java实现OpenID协议:OpenID4Java是对OpenID1.1和2.0规范的实现,目前它通过code.google.com系统进行维护。

此项目初始代码是由Sxip捐献出来的,而后Atlassian等公司参与进来,并为实现支持2.0规范(属性交换规范)的API贡献了大量的工作

参考资料来源:百度百科-OpenID

如何用java开发微信

说明:

本次的教程主要是对微信公众平台开发者模式的讲解,网络上很多类似文章,但很多都让初学微信开发的人一头雾水,所以总结自己的微信开发经验,将微信开发的整个过程系统的列出,并对主要代码进行讲解分析,让初学者尽快上手。

在阅读本文之前,应对微信公众平台的官方开发文档有所了解,知道接收和发送的都是xml格式的数据。另外,在做内容回复时用到了图灵机器人的api接口,这是一个自然语言解析的开放平台,可以帮我们解决整个微信开发过程中最困难的问题,此处不多讲,下面会有其详细的调用方式。

1.1在登录微信官方平台之后,开启开发者模式,此时需要我们填写url和token,所谓url就是我们自己服务器的接口,用WechatServlet.java来实现,相关解释已经在注释中说明,代码如下:

[java]view plaincopy

packagedemo.servlet;

importjava.io.BufferedReader;

importjava.io.IOException;

importjava.io.InputStream;

importjava.io.InputStreamReader;

importjava.io.OutputStream;

importjavax.servlet.ServletException;

importjavax.servlet.http.HttpServlet;

importjavax.servlet.http.HttpServletRequest;

importjavax.servlet.http.HttpServletResponse;

importdemo.process.WechatProcess;

/**

*微信服务端收发消息接口

*

*@authorpamchen-1

*

*/

publicclassWechatServletextendsHttpServlet{

/**

*ThedoGetmethodoftheservlet.<br>

*

*Thismethodiscalledwhenaformhasitstagvaluemethodequalstoget.

*

*@paramrequest

*therequestsendbytheclienttotheserver

*@paramresponse

*theresponsesendbytheservertotheclient

*@throwsServletException

*ifanerroroccurred

*@throwsIOException

*ifanerroroccurred

*/

publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)

throwsServletException,IOException{

request.setCharacterEncoding("UTF-8");

response.setCharacterEncoding("UTF-8");

/**读取接收到的xml消息*/

StringBuffersb=newStringBuffer();

InputStreamis=request.getInputStream();

InputStreamReaderisr=newInputStreamReader(is,"UTF-8");

BufferedReaderbr=newBufferedReader(isr);

Strings="";

while((s=br.readLine())!=null){

sb.append(s);

}

Stringxml=sb.toString();//次即为接收到微信端发送过来的xml数据

Stringresult="";

/**判断是否是微信接入激活验证,只有首次接入验证时才会收到echostr参数,此时需要把它直接返回*/

Stringechostr=request.getParameter("echostr");

if(echostr!=null&&echostr.length()>1){

result=echostr;

}else{

//正常的微信处理流程

result=newWechatProcess().processWechatMag(xml);

}

try{

OutputStreamos=response.getOutputStream();

os.write(result.getBytes("UTF-8"));

os.flush();

os.close();

}catch(Exceptione){

e.printStackTrace();

}

}

/**

*ThedoPostmethodoftheservlet.<br>

*

*Thismethodiscalledwhenaformhasitstagvaluemethodequalsto

*post.

*

*@paramrequest

*therequestsendbytheclienttotheserver

*@paramresponse

*theresponsesendbytheservertotheclient

*@throwsServletException

*ifanerroroccurred

*@throwsIOException

*ifanerroroccurred

*/

publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)

throwsServletException,IOException{

doGet(request,response);

}

}

1.2相应的web.xml配置信息如下,在生成WechatServlet.java的同时,可自动生成web.xml中的配置。前面所提到的url处可以填写例如:http;//服务器地址/项目名/wechat.do

[html]view plaincopy

<?xmlversion="1.0"encoding="UTF-8"?>

<web-appversion="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>ThisisthedescriptionofmyJ2EEcomponent</description>

<display-name>ThisisthedisplaynameofmyJ2EEcomponent</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通过以上代码,我们已经实现了微信公众平台开发的框架,即开通开发者模式并成功接入、接收消息和发送消息这三个步骤。

下面就讲解其核心部分——解析接收到的xml数据,并以文本类消息为例,通过图灵机器人api接口实现智能回复。

2.1首先看一下整体流程处理代码,包括:xml数据处理、调用图灵api、封装返回的xml数据。

[java]view plaincopy

packagedemo.process;

importjava.util.Date;

importdemo.entity.ReceiveXmlEntity;

/**

*微信xml消息处理流程逻辑类

*@authorpamchen-1

*

*/

publicclassWechatProcess{

/**

*解析处理xml、获取智能回复结果(通过图灵机器人api接口)

*@paramxml接收到的微信数据

*@return最终的解析结果(xml格式数据)

*/

publicStringprocessWechatMag(Stringxml){

/**解析xml数据*/

ReceiveXmlEntityxmlEntity=newReceiveXmlProcess().getMsgEntity(xml);

/**以文本消息为例,调用图灵机器人api接口,获取回复内容*/

Stringresult="";

if("text".endsWith(xmlEntity.getMsgType())){

result=newTulingApiProcess().getTulingResult(xmlEntity.getContent());

}

/**此时,如果用户输入的是“你好”,在经过上面的过程之后,result为“你也好”类似的内容

*因为最终回复给微信的也是xml格式的数据,所有需要将其封装为文本类型返回消息

**/

result=newFormatXmlProcess().formatXmlAnswer(xmlEntity.getFromUserName(),xmlEntity.getToUserName(),result);

returnresult;

}

}

2.2解析接收到的xml数据,此处有两个类,ReceiveXmlEntity.java和ReceiveXmlProcess.java,通过反射的机制动态调用实体类中的set方法,可以避免很多重复的判断,提高代码效率,代码如下:

[java]view plaincopy

packagedemo.entity;

/**

*接收到的微信xml实体类

*@authorpamchen-1

*

*/

publicclassReceiveXmlEntity{

privateStringToUserName="";

privateStringFromUserName="";

privateStringCreateTime="";

privateStringMsgType="";

privateStringMsgId="";

privateStringEvent="";

privateStringEventKey="";

privateStringTicket="";

privateStringLatitude="";

privateStringLongitude="";

privateStringPrecision="";

privateStringPicUrl="";

privateStringMediaId="";

privateStringTitle="";

privateStringDescription="";

privateStringUrl="";

privateStringLocation_X="";

privateStringLocation_Y="";

privateStringScale="";

privateStringLabel="";

privateStringContent="";

privateStringFormat="";

privateStringRecognition="";

publicStringgetRecognition(){

returnRecognition;

}

publicvoidsetRecognition(Stringrecognition){

Recognition=recognition;

}

publicStringgetFormat(){

returnFormat;

}

publicvoidsetFormat(Stringformat){

Format=format;

}

publicStringgetContent(){

returnContent;

}

publicvoidsetContent(Stringcontent){

Content=content;

}

publicStringgetLocation_X(){

returnLocation_X;

}

publicvoidsetLocation_X(StringlocationX){

Location_X=locationX;

}

publicStringgetLocation_Y(){

returnLocation_Y;

}

publicvoidsetLocation_Y(StringlocationY){

Location_Y=locationY;

}

publicStringgetScale(){

returnScale;

}

publicvoidsetScale(Stringscale){

Scale=scale;

}

publicStringgetLabel(){

returnLabel;

}

publicvoidsetLabel(Stringlabel){

Label=label;

}

publicStringgetTitle(){

returnTitle;

}

publicvoidsetTitle(Stringtitle){

Title=title;

}

publicStringgetDescription(){

returnDescription;

}

publicvoidsetDescription(Stringdescription){

Description=description;

}

publicStringgetUrl(){

returnUrl;

}

publicvoidsetUrl(Stringurl){

Url=url;

}

publicStringgetPicUrl(){

returnPicUrl;

}

publicvoidsetPicUrl(StringpicUrl){

PicUrl=picUrl;

}

publicStringgetMediaId(){

returnMediaId;

}

publicvoidsetMediaId(StringmediaId){

MediaId=mediaId;

}

publicStringgetEventKey(){

returnEventKey;

}

publicvoidsetEventKey(StringeventKey){

EventKey=eventKey;

}

publicStringgetTicket(){

returnTicket;

}

publicvoidsetTicket(Stringticket){

Ticket=ticket;

}

publicStringgetLatitude(){

returnLatitude;

}

publicvoidsetLatitude(Stringlatitude){

Latitude=latitude;

}

publicStringgetLongitude(){

returnLongitude;

}

publicvoidsetLongitude(Stringlongitude){

Longitude=longitude;

}

publicStringgetPrecision(){

returnPrecision;

}

publicvoidsetPrecision(Stringprecision){

Precision=precision;

}

publicStringgetEvent(){

returnEvent;

}

publicvoidsetEvent(Stringevent){

Event=event;

}

publicStringgetMsgId(){

returnMsgId;

}

publicvoidsetMsgId(StringmsgId){

MsgId=msgId;

}

publicStringgetToUserName(){

returnToUserName;

}

publicvoidsetToUserName(StringtoUserName){

微信java开发标准是什么

微信java开发标准是:

1、掌握xml解析工具Dom4j、Jdom中的任意一种,微信所有的消息处理都是xml,因此xml的解析就显得尤为重要,这集中体现在文本消息、图文消息这两个部分;

2、掌握JSON开发工具类,如jsonlibjson数据的处理,微信开发集中体现在自定义菜单接口、获取AccessToken、Oauth2点0网页授权等常用接口,此外第三方接口也会使用到如百度翻译、百度词典等;

3、掌握xstream,xstream的用途集中体现在java对象转xml字符串这个方面,使用xstream主要是为了最大程度地发挥java面向对象的特点;

4、熟悉MD5和SHA1加密算法,加密算法主要用于微信验证签名和生成签名(微信支付)两个部分;

5、掌握HTTPConnection和HTTPSConnecion,这个部分一般第二点配合使用以达到最佳效果;

6、掌握常用数据库;

7、能熟练使用linux操作系统。

关于微信用户 java代码是什么意思啊和微信java开发标准是什么的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

java企业级开发是什么,Java企业级开发是指什么 java中汉字用什么类型(汉字属于什么字符类型)