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

微信公众平台java

发布时间: 2022-06-27 19:36:48

① 微信公众平台 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

② 如何实现java程序与微信公众平台之间实现消息推送

java程序与微信公众平台之间实现消息推送方法:
1、本地数据库中存放着小程序用户表和微信公众号的表,下面就是向某一个小程序用户推送微信公众号信息
2、在小程序用户表中任意取一个用户A信息,用户A的openId和unionId,通过unionId到公众号表里去检索对应的A用户微信公众号的openId
3、在微信公众号上选择一个模板消息,编辑完要发送的的内容后,再请求发送模板消息的接口
关于微信公众号不能推送的,或者推送报错的,推送的miniprogram下的appid对应的小程序必须是已审核并发布的才可以推送。
推送软件用极光推送,实现多种消息类型,开发者可以轻松地通过极光发送各个移动平台的系统通知,还可以在控制台编辑多种富文本展示模板; 极光还提供自定义消息的透传,客户端接到消息内容后根据自己的逻辑自由处理。

③ 如何用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微信公众号怎么做

这个问题太广泛了,只能简单和您说明一下。首先注册微信公众号,然后使用java开发服务器并与微信后台服务器完成验证。根据实际的需求与微信开发文档即可进行功能开发

⑤ 微信公众平台可以用java写吗

可以,我现在的项目就是java后台开发的微信公众平台,唯一要注意的就是公众平台openid的使用

⑥ 初学微信公众号使用java开发,出现错误,提示公众号服务出现故障,怎么办,求大神指点迷津!

1,你可以看一下编程工具里有没有出现错误提示
2,设置一些输出点,用来检查代码
3,确保你的appid和token填写正确
4,确保你的公众号有这个权限
5,所需的外网能放问的域名配置正确

⑦ 怎么搭建微信公众平台java开发环境

这个比较复杂,首先需要申请一个微信公众的订阅好或服务号,还要开通各种接口,然后在本地安装java开发环境,包括开发工具如eclipse,myeclipse。最重要的是能在公网有一个地址映射到本地,如果是在局域网,则需要借助第三方工具,推荐使用花生壳、nat123,其中nat123是个比较好的工具,很好的解决了运营商80端口封锁的问题,因为微信公众平台配置服务器的URL只能是80端口。有什么不清楚的可以私信我。

⑧ 【Java】微信公众平台开发视频教程【共8G】

uni

链接: https://pan..com/s/1ad1Y2dX4VCJ0eIPSiuC5dQ

提取码: hyy3 复制这段内容后打开网络网盘手机App,操作更方便哦

若资源有问题欢迎追问~

⑨ 微信公众平台能用java开发吗

完全可以,微信公众平台的后台实际上就是一个WEB项目,能够开发WEB项目的语言环境都可以实现

⑩ 微信公众平台有 java sdk 吗

微信公众平台有自己的java sdk的,微信公众平台也是一个开发平台,他们对第三方开发企业开放接口,让更多微信公众平台运营人员使用第三方的工具,如活动推送工具,可以对接【活动盒子】的java sdk,支付工具,客服工具这些的sdk也都可以对接。

热点内容
安卓哪里填写apple代码 发布:2025-02-05 00:28:54 浏览:287
oppo手机锁屏密码忘记后如何更换 发布:2025-02-05 00:28:19 浏览:24
幼儿思维编程 发布:2025-02-05 00:18:21 浏览:24
我的世界电脑正版如何进入服务器 发布:2025-02-05 00:18:06 浏览:879
疫情防控健康码预警机制演练脚本 发布:2025-02-04 23:58:46 浏览:38
分治算法java 发布:2025-02-04 23:41:15 浏览:592
安卓app点进去就闪退怎么回事 发布:2025-02-04 23:36:56 浏览:779
宏按键编程 发布:2025-02-04 23:05:11 浏览:904
微信隐形密码在哪里设置 发布:2025-02-04 23:05:01 浏览:866
android的补间动画 发布:2025-02-04 23:03:42 浏览:416