当前位置:首页 » 编程语言 » java开发微信平台开发

java开发微信平台开发

发布时间: 2024-05-01 09:47:54

‘壹’ 微信小程序的开发需要掌握哪些开发语言

1、学习html/css/js三件套

html:超文本标记语言(英语:HyperTextMarkupLanguage,简称:HTML)是一种用于创建网页的标准标记语言。您可以使用HTML来建立自己的WEB站点,HTML运行在浏览器上,由浏览器来解析。

css:css是CascadingStyleSheets的缩写,我们中文称为“串联样式表”,能让我们更精确的控制网页版面的文字、背景、字型等它能让我们只修正一个css文件,便可同时更新众多的网页版面外观及格式,还可以使html的文件内码更精简,缩小档案下载的指备带速度。

js:js是javascript的缩写形式,而Javascript是一种基于对象和事件驱动并且具有相对安全性的客户端脚本语言。它在Web开发中JS占据着举足轻重的地位,所有交互、逻辑层的代码都应该由它来实现。

2、php/JAVA语言开发

对于微信小程序而言,前端程序是唯一差异于网站建设技术的,因此,只要前端程序过得了关,能够写前端的接口,那么您使用PHP,又或者java,以及asp.net的程序语言都是完全支持的。一般对于企业而言,都是采用php程序开发微信小程序;技术要求高一点的滚镇可以采用java程序开发。这些唯芦开发方式成都锐美网络都已实践,且能保证效果。

微信小程序常见使用“MINA”框架,ApacheMinaServer是一个网络通信应用框架,也就是说,它主要是对基于TCP/IP、UDP/IP协议栈的通信框架,Mina可以帮助开发者快速开发高性能、高扩展性的网络通信应用,Mina提供了事件驱动、异步(Mina的异步IO默认使用的是JAVANIO作为底层支持)操作的编程模型。这个框架为微信小程序的运行提供了丰富的组件和API。微信小程序开发者要学会和掌握小程序的框架结构、数据绑定机制、模板、数据缓存、常用组件和API等相关知识。

‘贰’ java程序员学做微信开发容易不,求java微信开发的教程资源

其实Java程序员要自学安卓开发的基础知识还是没有什么难度的,毕竟语言相通,特性相似,阅读安卓源代码的门槛以比较低一些,作为能够考虑“转”的合格的程序员的你,自学能力和相关的基础知识应该不是问题,学习安卓也相对比较轻松一些。

所以Java程序员转安卓开发可以看做是一次“增量更新”,只需要学习一下安卓的基本组件:Activity、ContentProvider、Service、BroadcastReceiver;
了解一下安卓中的Intent,Handler,Adapter以及各类事件的传递方式(onClick,onTouch等);

同时辅助一定的代码量,像JNI、AIDL什么的都可以看一下;你还要摒弃“UI元素像素位置”这个概念,安卓本身是允许通过设定元素位置来制作UI的,如果你这样做导致的结果便是大批机器不适配,那么显示效果就有点惨不忍睹了,所以不要妄想通过获取屏幕大小来调整UI,像LinearLayout在swing或者swt上可有可无的东西,在安卓上是必须要精通的。

‘叁’ 如何用java开发微信

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

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


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

[java]view plain

  • 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

  • *

  • */

  • {

  • /**

  • *ThedoGetmethodoftheservlet.<br>

  • *

  • *.

  • *

  • *@paramrequest

  • *

  • *@paramresponse

  • *

  • *@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>

  • *

  • *

  • *post.

  • *

  • *@paramrequest

  • *

  • *@paramresponse

  • *

  • *@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 plain

  • <?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></description>

  • <display-name></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 plain

  • 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 plain

  • 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开发 能用oracle数据库

微信公众平台是可以开发java调用oracle这类型的接口的,一般通过MyBatis连接Oracle数据库。

举例如下:
1、先建立一个数据库表,名为PERSON_INFO,建表sql如下:

createTABLEPERSON_INFO

(

idnumber(12,0)PRIMARYKEY,

namevarchar2(20)NOTNULL,

genderchar(1)DEFAULT'',

remarkvarchar2(1000),

input_datenumber(10,0)DEFAULTto_number(to_char(sysdate,'yyyymmdd')),

input_timenumber(10,0)DEFAULTto_number(to_char(sysdate,'hh24miss'))

);

2、编写java程序,项目中文件的上下级关系如图:

5、建立对应的Java类:PersonInfo,其中各属性对应于数据表PERSON_INFO中的各字段

publicclassPersonInfo{

Longid;

Stringname;

Stringgender;

Stringremark;

LonginputDate;

LonginputTime;

publicLonggetId(){

returnid;

}

publicvoidsetId(Longid){

this.id=id;

}

publicStringgetName(){

returnname;

}

publicvoidsetName(Stringname){

this.name=name;

}

publicStringgetGender(){

returngender;

}

publicvoidsetGender(Stringgender){

this.gender=gender;

}

publicStringgetRemark(){

returnremark;

}

publicvoidsetRemark(Stringremark){

this.remark=remark;

}

publicLonggetInputDate(){

returninputDate;

}

publicvoidsetInputDate(LonginputDate){

this.inputDate=inputDate;

}

publicLonggetInputTime(){

returninputTime;

}

publicvoidsetInputTime(LonginputTime){

this.inputTime=inputTime;

}

}

6、建立对应的Java类:PersonInfoMapper

importjava.util.List;

{

List<PersonInfo>selectAllPersonInfo();

7、建立一个类MyBatisTest用于存放main函数,查询PERSON_INFO表中所有的数据并打印

importjava.io.InputStream;

importjava.util.List;

importorg.apache.ibatis.io.Resources;

importorg.apache.ibatis.session.SqlSession;

importorg.apache.ibatis.session.SqlSessionFactory;

importorg.apache.ibatis.session.SqlSessionFactoryBuilder;

/**

*MyBatis使用测试

*@author pieryon

*@date2016年4月1日

*@time下午21:47:01

*@remark

*

*/

publicclassMyBatisTest{

publicstaticvoidmain(String[]args){

try{

Stringresource="mybatis-config.xml";

InputStreaminputStream=Resources.getResourceAsStream(resource);

=newSqlSessionFactoryBuilder().build(inputStream);

SqlSessionsession=sqlSessionFactory.openSession();

try{

PersonInfoMappermapper=session.getMapper(PersonInfoMapper.class);

List<PersonInfo>personInfos=mapper.selectAllPersonInfo();

if(personInfos==null){

System.out.println("Theresultisnull.");

}else{

for(PersonInfopersonInfo:personInfos){

System.out.println("---PersonInfo---");

System.out.println("name:"+personInfo.name);

System.out.println("gender:"+personInfo.gender);

System.out.println("remark:"+personInfo.remark);

System.out.println("inputDate:"+personInfo.inputDate);

System.out.println("inputTime:"+personInfo.inputTime);

System.out.println();

}

}

}finally{

session.close();

}

}catch(Exceptionex){

ex.printStackTrace();

}

}

}

8、运行main函数,控制台输出结果如下:

---PersonInfo---
name:Tsybius
gender:m
remark:-
inputDate:20160229
inputTime:225703

---PersonInfo---
name:Galatea
gender:f
remark:-
inputDate:20160228
inputTime:123456

热点内容
简单的asp网站源码 发布:2024-05-21 18:40:19 浏览:665
苹果和安卓哪个适合入手 发布:2024-05-21 18:35:25 浏览:291
xheditor上传文件 发布:2024-05-21 18:30:16 浏览:932
不同网络如何访问公司服务器 发布:2024-05-21 18:28:18 浏览:780
基岩版uhc服务器ip 发布:2024-05-21 17:56:48 浏览:948
java源代码反编译专家 发布:2024-05-21 17:48:45 浏览:156
yunos的密码是多少 发布:2024-05-21 17:37:26 浏览:953
php时间今天 发布:2024-05-21 17:34:39 浏览:58
脚本开机自动运行 发布:2024-05-21 17:33:43 浏览:275
为什么安卓手机内存总剩一半 发布:2024-05-21 17:33:03 浏览:893