Mkey3g開發了解
1. 首先在數字天堂官網注冊,下載下傳激活碼!!
2. 安裝mkey3g所需要的Tomcat,MySql并将mkey3gdb資料庫導入到MySql中,以供mkey3g配置檔案能打開,在打開的mkey3g配置頁面中配置登陸方式和透傳位址,隻需要配置如圖的兩項即可
3. 裝好手機應用用戶端
4. 在mkey3g檔案夾中的app檔案夾中的global.xml配置登陸的xml檔案
5. 登陸先省略
6. 配置home.xml以顯示手機用戶端的應用程式
如圖:
7.開發其中的應用程式(以理賠查詢為例)
首先需要産生這樣一個頁面則需要寫一個xml檔案(需用數字天堂開發的識别格式)
如:
<?xml version="1.0" encoding="UTF-8"?>
<dhmi type="response">
<msc type="form" name="initform" action="[email protected]&inter>
<head>
<script type="text/javascript">
<![CDATA[
function submit(){
document.initform.submit();
}
]]>
</script>
</head>
<body>
<span dock="top" align="center" width="100%">
<img src="img/allMaterial/top.png"/>
</span>
<span width="100%" height="10"/>
<span>
<img src="res:allow_r.png"/>
<font color="#ff0000">理賠查詢</font>
</span>
<span width="100%">
<span width="30%">客戶姓名:</span><input name="CUSTOMERNAME" type="text" value=""/>
<span width="30%">身份證号:</span><input name="ORGANIZECODE" type="text" value=""></input>
</span>
<span width="100%" align="left">
<span width="30%" align="center"><img src="img/query_btn.png" href="script:submit()"></img></span>
</span>
<br/>
</body>
</msc>
</dhmi>
需以dhmi為根目錄,msc則類似html标簽,注意其javascript寫法,在這裡不叫javascript而叫DHS,action的配置需以?action= [email protected]&這是規定
7. interfont-size: 10pt; color: #2a00ff; font-family: "Courier New"; mso-font-kerning: 0pt;'>lipei_chaxun則是配置在dhmi_access_config.properties屬性檔案中在啟動時讀取并初始化其中的資料。
8. 将寫好理賠查詢登陸頁面發送到伺服器,而伺服器并不認識,則需要将此xml轉為伺服器認識的xml,先寫一個轉換xml格式的xsl定好節點格式.
如:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<CarQuoteCustomerInfoQueReq>
<ReqHead>
<UUID>待确定</UUID>
<REQUESTTYPE>Q06</REQUESTTYPE>
<FLOWINTIME>時間要在java代碼中填寫</FLOWINTIME>
</ReqHead>
<CUSTOMERCODE/>
<CUSTOMERCNAME>
<xsl:value-of select="//CUSTOMERNAME/text()"/>
</CUSTOMERCNAME>
<ORGANIZECODE>
<xsl:value-of select="//ORGANIZECODE/text()"/>
</ORGANIZECODE>
<POLICYNO/>
</CarQuoteCustomerInfoQueReq>
</xsl:template>
</xsl:stylesheet>
9. 在背景伺服器寫代碼将請求過來的xml檔案轉換成可以識别的xml檔案在取其中所需節點的值,再做業務編碼!!
如:
private static Properties config = SysConfig.getConfig("connector_config.properties");
private Logger logger = Logger.getLogger(PaymentInfoAccess.class);
@SuppressWarnings("unchecked")
@Override
public Document invoke(Document reqDoc) {
logger.debug(reqDoc.asXML());
//
Document rspDoc = null;
try{
//客戶資訊查詢頁面結果傳回
reqDoc = XMLHelper.dom4jXsltTransferXml(reqDoc, "payment/DHMI_lipei_MDSP.xsl");
Element rootEle = reqDoc.getRootElement();
Element custName = (Element)rootEle.selectSingleNode("/CarQuoteCustomerInfoQueReq/CUSTOMERCNAME");
Element custNo = (Element)rootEle.selectSingleNode("/CarQuoteCustomerInfoQueReq/ORGANIZECODE");
if(custName.getText().equals("") && custNo.getText().equals("")){
String msg = "客戶名稱和身份證号不能同時為空!";
rspDoc = transeferErrorMsgToXML(msg);
}else{
// ServletConnector servletConnector = new ServletConnector("CarQuoteCustomerInfoQueReq");
// String rspString = (String)servletConnector.callService(reqDoc.asXML());
// String rspString = UtilHelp.rspString;
rspDoc = XMLHelper.parseXML(UtilHelp.rspString);
List<Element> customerInfoList = rspDoc.selectNodes("/body/CarQuoteInfoQueRsp/CarQuoteCustomerInfoList/CarQuoteCustomerInfo");
if(customerInfoList.size() == 1){
//如果客戶名稱和身份證号都輸入則隻有一條記錄,取出其中的客戶代碼
Element custInfoEle = (Element)customerInfoList.get(0);
String customerCode = "";
customerCode = (custInfoEle.selectSingleNode("CUSTOMERCODE")).getText();
rspDoc = new PaymentInfoListAccess(customerCode).invoke(rspDoc);
}else{
//如果隻輸入使用者名則可能有多條客戶資訊(顯示多條客戶資訊的客戶代碼和名稱)
//
List<String[]> custList = new ArrayList<String[]>();
for(Element custEle : customerInfoList){
String[] custArray = new String[]{custEle.selectSingleNode("CUSTOMERCNAME").getText(),
custEle.selectSingleNode("CUSTOMERCODE").getText()};
custList.add(custArray);
}
//将此List資料put到xsl中
rspDoc = transferCustInfoToXML(custList);
}
}
}catch(Exception e){
e.printStackTrace();
}
return rspDoc;
}
public CustomerWebServicesPortType getCustomerWebServicesConnector(String url) {
CustomerWebServices service = new CustomerWebServicesLocator();
CustomerWebServicesPortType connector = null;
try {
connector = service.getCustomerWebServicesHttpPort(new URL(config.getProperty(url)));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
return connector;
}
public Document transferCustInfoToXML(List<String[]> list){
Document custInfoDoc = null;
custInfoDoc = DocumentHelper.createDocument();
Element rootEle = custInfoDoc.addElement("CustInfo");
for(String[] custArr : list){
Element custData = rootEle.addElement("CustData");
custData.addElement("CustomerName").setText(custArr[0]);
custData.addElement("CustomerCode").setText(custArr[1]);
}
System.out.println(custInfoDoc.asXML());
custInfoDoc = XMLHelper.dom4jXsltTransferXml(custInfoDoc, "payment/customer_info.xsl");
System.out.println(custInfoDoc.asXML());
return custInfoDoc;
}
public Document transeferErrorMsgToXML(String errormsg){
Document rspDoc = null;
rspDoc = DocumentHelper.createDocument();
Element ele = rspDoc.addElement("body");
ele.addElement("error").setText(errormsg);
rspDoc = XMLHelper.dom4jXsltTransferXml(rspDoc, "payment/lipei_cx_warning.xsl");
return rspDoc;
}
10. 相關代碼示例:
private Logger log = Logger.getLogger(PaymentInfoListAccess.class);
private static Properties config = SysConfig.getConfig("connector_config.properties");
private String customer_code = "";
public PaymentInfoListAccess(){}
public PaymentInfoListAccess(String customerCode){
customer_code = customerCode;
}
@Override
public Document invoke(Document reqDoc) {
log.debug(reqDoc.asXML());
Document rspDoc = null;
try{
//一個客戶可能有多個保單
// CustomerWebServicesPortType client = getCustomerWebServicesConnector("PaymentInfo");
// PrpLRegistCustCarVo[] vo = client.findPrpLcustRegistCarByCustomerCodes(customer_code);
UtilHelp.init();
List<PrpLRegistCustCarVo> custList = transferArrayToList(UtilHelp.vo);
if(customer_code.equals("")){
customer_code=reqDoc.selectSingleNode("//dhmi/data/customerCode").getText();
}
rspDoc = transferPaymentInfoToXML(custList, customer_code);
rspDoc = XMLHelper.dom4jXsltTransferXml(rspDoc, "payment/lipei_cx_list.xsl");
}catch(Exception e){
e.printStackTrace();
}
return rspDoc;
}
public CustomerWebServicesPortType getCustomerWebServicesConnector(String url) {
CustomerWebServices service = new CustomerWebServicesLocator();
CustomerWebServicesPortType connector = null;
try {
connector = service.getCustomerWebServicesHttpPort(new URL(config.getProperty(url)));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
return connector;
}
private List<PrpLRegistCustCarVo> transferArrayToList(PrpLRegistCustCarVo[] vo){
List<PrpLRegistCustCarVo> custList = new ArrayList<PrpLRegistCustCarVo>();
for(int i = 0 ; i < vo.length ; i++){
custList.add(vo[i]);
}
return custList;
}
public Document transferPaymentInfoToXML(List<PrpLRegistCustCarVo> list,String customerCode){
Document paymentInfoDoc = null;
paymentInfoDoc = DocumentHelper.createDocument();
Element rootElement = paymentInfoDoc.addElement("body");
for(PrpLRegistCustCarVo vo : list){
Element payment = rootElement.addElement("payment");
//客戶代碼
payment.addElement("CUSTOMERCODE").setText(customerCode);
//狀态
payment.addElement("STATUS").setText(vo.getRegistState());
//報案号
payment.addElement("REGISTNO").setText(vo.getRegistNo());
}
return paymentInfoDoc;
}
通過這些代碼則可以出來一個清單頁面:
11. 點選其中的某項的頁面
12. 其實這些都是通過一系列的xml和對xml轉換的xsl來做的
13. 比如要将10中的清單頁面顯示出來則需要配置一個顯示清單的xsl
如:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<dhmi type="response">
<msc type="form" showfoot="true">
<head>
<title>手機遠端銷售系統</title>
</head>
<body background="img/allMaterial/bg.png">
<span dock="top" align="center" width="100%">
<img src="img/allMaterial/top.png"/>
</span>
<span width="100%" height="10"/>
<listbox id="firstCust" visible="true">
<xsl:apply-templates mode="all" select="/body/payment"></xsl:apply-templates>
</listbox>
</body>
</msc>
</dhmi>
</xsl:template>
<xsl:template match="/body/payment" mode="all">
<xsl:variable name="customerCode" select="CUSTOMERCODE"/>
<xsl:variable name="status" select="STATUS"/>
<xsl:variable name="registNo" select="REGISTNO"/>
<listitem target="_blank" icon="img/Notice/star.png" value="000" href="[email protected]&inter>
<caption>
報案号:<xsl:value-of select="$registNo"></xsl:value-of>(
<xsl:choose>
<xsl:when test="$status = 0">未決</xsl:when>
<xsl:otherwise>已決</xsl:otherwise>
</xsl:choose>
)
</caption>
<sndcaption>
客戶代碼:<xsl:value-of select="$customerCode"></xsl:value-of>
</sndcaption>
<digest>
客戶代碼:<xsl:value-of select="$customerCode"></xsl:value-of>
</digest>
</listitem>
</xsl:template>
</xsl:stylesheet>
再經過10的解析封裝成一個xml格式的xml不需加<dhmi>和<msc>标簽,因為此為傳回到手機用戶端的xml,在經過mkey3g中間件時通過下行模闆會自動進行拼裝.到手機用戶端後則可以正常顯示了
14. 流程示範;