本文目錄一覽:
- 1、微信公眾平台 java開發 能用oracle資料庫嗎
- 2、微信是用什麼語言開發的
- 3、如何用java開發微信
- 4、能用java做微信二次開發嗎
- 5、怎麼搭建微信公眾平台java開發環境??
- 6、如何使用java設計一個微信小程序?
微信公眾平台 java開發 能用oracle資料庫嗎
微信公眾平台是可以開發java調用oracle這類型的介面的,一般通過MyBatis連接Oracle資料庫。
舉例如下:
1、先建立一個資料庫表,名為PERSON_INFO,建表SQL如下:
create TABLE PERSON_INFO
(
id number(12,0) PRIMARY KEY,
name varchar2(20) NOT NULL,
gender char(1) DEFAULT ‘ ‘,
remark varchar2(1000),
input_date number(10,0) DEFAULT to_number(to_char(sysdate,’yyyymmdd’)),
input_time number(10,0) DEFAULT to_number(to_char(sysdate,’hh24miss’))
);
2、編寫java程序,項目中文件的上下級關係如圖:
3、構建mybatis配置映射關係
1)、導入JAR包:mybatis-3.2.2.jar、ojdbc14-10.2.0.2.0.jar
2)、建立MyBatis配置文件mybatis-config.xml
4、建立xml文件:PersonInfoMapper.xml,其中實現了一個SQL語句:selectAllPersonInfo,查詢所有的PERSON_INFO信息
5、建立對應的Java類:PersonInfo,其中各屬性對應於數據表PERSON_INFO中的各欄位
public class PersonInfo {
Long id;
String name;
String gender;
String remark;
Long inputDate;
Long inputTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Long getInputDate() {
return inputDate;
}
public void setInputDate(Long inputDate) {
this.inputDate = inputDate;
}
public Long getInputTime() {
return inputTime;
}
public void setInputTime(Long inputTime) {
this.inputTime = inputTime;
}
}
6、建立對應的Java類:PersonInfoMapper
import java.util.List;
public interface PersonInfoMapper {
ListPersonInfo selectAllPersonInfo();
7、建立一個類MyBatisTest用於存放main函數,查詢PERSON_INFO表中所有的數據並列印
import java.io.InputStream;
import java.util.List;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
/**
* MyBatis使用測試
* @author pieryon
* @date 2016年4月1日
* @time 下午21:47:01
* @remark
*
*/
public class MyBatisTest {
public static void main(String[] args) {
try {
String resource = “mybatis-config.xml”;
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession session = sqlSessionFactory.openSession();
try {
PersonInfoMapper mapper = session.getMapper(PersonInfoMapper.class);
ListPersonInfo personInfos = mapper.selectAllPersonInfo();
if (personInfos == null) {
System.out.println(“The result is null.”);
} else {
for (PersonInfo personInfo : 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 (Exception ex) {
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為主的程序語言開發的,包括微信。
許多的 Android應用都是Java程序員開發者開發。雖然 Android運用了不同的JVM以及不同的封裝方式,但是代碼還是用Java語言所編寫。相當一部分的手機中都支持JAVA遊戲,這就使很多非編程人員都認識了JAVA。
擴展資料
Java 語言是一門隨時代快速發展的計算機語言程序,其深刻展示了程序編寫的精髓,加上其簡明嚴謹的結構及簡潔的語法編寫為其將來的發展及維護提供了保障。由於提供了網路應用的支持和多媒體的存取,會推動Internet和企業網路的Web的應用 。
另外,為了保持Java的增長和推進Java社區的參與,Sun公司在Java One開發者大會上宣布開放Java核心源代碼,以鼓勵更多的人參與到Java社團活動中。來自Java社團和IBM等全球技術合作夥伴兩方面的支持,
Java技術在創新和社會進步上繼續發揮強有力的重要作用,並且隨著其程序編寫難度的降低使得更多專業人員將精力放置於Java語言的編寫與框架結構的設計中。
如何用java開發微信
說明:
本次的教程主要是對微信公眾平台開發者模式的講解,網路上很多類似文章,但很多都讓初學微信開發的人一頭霧水,所以總結自己的微信開發經驗,將微信開發的整個過程系統的列出,並對主要代碼進行講解分析,讓初學者儘快上手。
在閱讀本文之前,應對微信公眾平台的官方開發文檔有所了解,知道接收和發送的都是xml格式的數據。另外,在做內容回復時用到了圖靈機器人的api介面,這是一個自然語言解析的開放平台,可以幫我們解決整個微信開發過程中最困難的問題,此處不多講,下面會有其詳細的調用方式。
1.1 在登錄微信官方平台之後,開啟開發者模式,此時需要我們填寫url和token,所謂url就是我們自己伺服器的介面,用WechatServlet.java來實現,相關解釋已經在注釋中說明,代碼如下:
[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;
/**
* 微信服務端收發消息介面
*
* @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 sb = 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) {
sb.append(s);
}
String xml = sb.toString(); //次即為接收到微信端發送過來的xml數據
String result = “”;
/** 判斷是否是微信接入激活驗證,只有首次接入驗證時才會收到echostr參數,此時需要把它直接返回 */
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 相應的web.xml配置信息如下,在生成WechatServlet.java的同時,可自動生成web.xml中的配置。前面所提到的url處可以填寫例如:http;//伺服器地址/項目名/wechat.do
[html] view plain copy
?xml version=”1.0″ encoding=”UTF-8″?
web-app version=”2.5″
xmlns=””
xmlns:xsi=””
xsi:schemaLocation=”
“
servlet
descriptionThis is the description of my J2EE component/description
display-nameThis is the display name of my J2EE component/display-name
servlet-nameWechatServlet/servlet-name
servlet-classdemo.servlet.WechatServlet/servlet-class
/servlet
servlet-mapping
servlet-nameWechatServlet/servlet-name
url-pattern/wechat.do/url-pattern
/servlet-mapping
welcome-file-list
welcome-fileindex.jsp/welcome-file
/welcome-file-list
/web-app
1.3 通過以上代碼,我們已經實現了微信公眾平台開發的框架,即開通開發者模式並成功接入、接收消息和發送消息這三個步驟。
下面就講解其核心部分——解析接收到的xml數據,並以文本類消息為例,通過圖靈機器人api介面實現智能回復。
2.1 首先看一下整體流程處理代碼,包括:xml數據處理、調用圖靈api、封裝返回的xml數據。
[java] view plain copy
package demo.process;
import java.util.Date;
import demo.entity.ReceiveXmlEntity;
/**
* 微信xml消息處理流程邏輯類
* @author pamchen-1
*
*/
public class WechatProcess {
/**
* 解析處理xml、獲取智能回復結果(通過圖靈機器人api介面)
* @param xml 接收到的微信數據
* @return 最終的解析結果(xml格式數據)
*/
public String processWechatMag(String xml){
/** 解析xml數據 */
ReceiveXmlEntity xmlEntity = new ReceiveXmlProcess().getMsgEntity(xml);
/** 以文本消息為例,調用圖靈機器人api介面,獲取回復內容 */
String result = “”;
if(“text”.endsWith(xmlEntity.getMsgType())){
result = new TulingApiProcess().getTulingResult(xmlEntity.getContent());
}
/** 此時,如果用戶輸入的是「你好」,在經過上面的過程之後,result為「你也好」類似的內容
* 因為最終回復給微信的也是xml格式的數據,所有需要將其封裝為文本類型返回消息
* */
result = new FormatXmlProcess().formatXmlAnswer(xmlEntity.getFromUserName(), xmlEntity.getToUserName(), result);
return result;
}
}
2.2 解析接收到的xml數據,此處有兩個類,ReceiveXmlEntity.java和ReceiveXmlProcess.java,通過反射的機制動態調用實體類中的set方法,可以避免很多重複的判斷,提高代碼效率,代碼如下:
[java] view plain copy
package demo.entity;
/**
* 接收到的微信xml實體類
* @author pamchen-1
*
*/
public class ReceiveXmlEntity {
private String ToUserName=””;
private String FromUserName=””;
private String CreateTime=””;
private String MsgType=””;
private String MsgId=””;
private String Event=””;
private String EventKey=””;
private String Ticket=””;
private String Latitude=””;
private String Longitude=””;
private String Precision=””;
private String PicUrl=””;
private String MediaId=””;
private String Title=””;
private String Description=””;
private String Url=””;
private String Location_X=””;
private String Location_Y=””;
private String Scale=””;
private String Label=””;
private String Content=””;
private String Format=””;
private String Recognition=””;
public String getRecognition() {
return Recognition;
}
public void setRecognition(String recognition) {
Recognition = recognition;
}
public String getFormat() {
return Format;
}
public void setFormat(String format) {
Format = format;
}
public String getContent() {
return Content;
}
public void setContent(String content) {
Content = content;
}
public String getLocation_X() {
return Location_X;
}
public void setLocation_X(String locationX) {
Location_X = locationX;
}
public String getLocation_Y() {
return Location_Y;
}
public void setLocation_Y(String locationY) {
Location_Y = locationY;
}
public String getScale() {
return Scale;
}
public void setScale(String scale) {
Scale = scale;
}
public String getLabel() {
return Label;
}
public void setLabel(String label) {
Label = label;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public String getUrl() {
return Url;
}
public void setUrl(String url) {
Url = url;
}
public String getPicUrl() {
return PicUrl;
}
public void setPicUrl(String picUrl) {
PicUrl = picUrl;
}
public String getMediaId() {
return MediaId;
}
public void setMediaId(String mediaId) {
MediaId = mediaId;
}
public String getEventKey() {
return EventKey;
}
public void setEventKey(String eventKey) {
EventKey = eventKey;
}
public String getTicket() {
return Ticket;
}
public void setTicket(String ticket) {
Ticket = ticket;
}
public String getLatitude() {
return Latitude;
}
public void setLatitude(String latitude) {
Latitude = latitude;
}
public String getLongitude() {
return Longitude;
}
public void setLongitude(String longitude) {
Longitude = longitude;
}
public String getPrecision() {
return Precision;
}
public void setPrecision(String precision) {
Precision = precision;
}
public String getEvent() {
return Event;
}
public void setEvent(String event) {
Event = event;
}
public String getMsgId() {
return MsgId;
}
public void setMsgId(String msgId) {
MsgId = msgId;
}
public String getToUserName() {
return ToUserName;
}
public void setToUserName(String toUserName) {
能用java做微信二次開發嗎
若是微信提供了sdk,你就比較容易做二次開發了。微信是騰訊的產品,你要做什麼二次開發?java可以開發任意的安卓軟體安卓版的微信沒有任何問題安卓開發就是java語言應用的一個大方向!!別的我就不多說了當然可以用java語言進行微信的二次開發呀
怎麼搭建微信公眾平台java開發環境??
這個比較複雜,首先需要申請一個微信公眾的訂閱好或服務號,還要開通各種介面,然後在本地安裝java開發環境,包括開發工具如eclipse,myeclipse。最重要的是能在公網有一個地址映射到本地,如果是在區域網,則需要藉助第三方工具,推薦使用花生殼、nat123,其中nat123是個比較好的工具,很好的解決了運營商80埠封鎖的問題,因為微信公眾平台配置伺服器的URL只能是80埠。有什麼不清楚的可以私信我。
如何使用java設計一個微信小程序?
Java不能設計微信小程序,微信小程序開發有其自己的語言和文件形式。Java可以作為微信小程序的服務端語言和api介面伺服器語言為小程序端提供服務,而不是直接開發微信小程序。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/271962.html