手机号在线时长接口调用相关后续代码

This commit is contained in:
jianghongdong 2018-08-11 15:31:36 +08:00
parent 705b90ffb5
commit b33b31518b
5 changed files with 235 additions and 53 deletions

View File

@ -8,6 +8,7 @@
//初始话手机在线时长查询
String ProjectId = CurPage.getParameter("ProjectId");
String flowunid = CurPage.getParameter("ObjectNo");
ASObjectModel doTemp = new ASObjectModel("LbTelOnlinList");
ASObjectWindow dwTemp = new ASObjectWindow(CurPage,doTemp,request);
dwTemp.Style="1"; //--设置为Grid风格--
@ -17,24 +18,29 @@
//0、是否展示 1、 权限控制 2、 展示类型 3、按钮显示名称 4、按钮解释文字 5、按钮触发事件代码 6、 7、 8、 9、图标CSS层叠样式 10、风格
String sButtons[][] = {
// {"true","All","Button","新增","新增","newRecord()","","","","btn_icon_add",""},
// {"true","","Button","详情","详情","viewAndEdit()","","","","btn_icon_detail",""},
// {"true","","Button","删除","删除","if(confirm('确实要删除吗?'))as_delete(0,'alert(getRowCount(0))')","","","","btn_icon_delete",""},
{"true","","Button","校验手机号在线时长","调用查询接口","checkPhoneNumberOnLine()","","","","btn_icon_detail",""},
{"true","All","Button","重发","选择需要重新查询的某条数据","retry()","","","","btn_icon_detail",""},
};
%><%@include file="/Frame/resources/include/ui/include_list.jspf"%>
<script type="text/javascript">
function newRecord(){
var sUrl = "";
AsControl.OpenView(sUrl,'','_self','');
function checkPhoneNumberOnLine(){
var result = RunJavaMethodTrans("com.tenwa.lease.flow.project.validate.OnlineClient","getTelOnLine","flowunid=<%=flowunid%>,projectId=<%=ProjectId%>");
if(result=="true"){
window.location.reload();
}else{
AsDebug.showMessage('提示',result,'','',true);
}
}
function viewAndEdit(){
var sUrl = "";
var sPara = getItemValue(0,getRow(0),'SerialNo');
if(typeof(sPara)=="undefined" || sPara.length==0 ){
alert("参数不能为空!");
return ;
}
AsControl.OpenView(sUrl,'SerialNo=' +sPara ,'_self','');
function retry(){
var onLineId = getItemValue(0,getRow(0),'online_id');
var result = RunJavaMethodTrans("com.tenwa.lease.flow.project.validate.OnlineClient","getTelOnLineReTry","onLineId="+onLineId);
if(result=="true"){
window.location.reload();
}else{
AsDebug.showMessage('提示',result,'','',true);
}
}
</script>
<%@ include file="/Frame/resources/include/include_end.jspf"%>

View File

@ -4227,6 +4227,7 @@
<class name="LB_TELONLINE" label="手机号在线时长" keyAttributes="ID">
<attributes>
<attribute name="ID" label="ID" type="STRING" length="40"/>
<attribute name="online_id" label="调用返回id" type="STRING" length="40"/>
<attribute name="success" label="是否调用成功" type="STRING" length="10"/>
<attribute name="reason_code" label="调用失败时的错误码" type="STRING" length="20"/>
<attribute name="reason_desc" label="错误详情描述" type="STRING" length="500"/>

View File

@ -0,0 +1,11 @@
#测试请求地址
com.tenwa.jianghd.url1=https
com.tenwa.jianghd.url2=apitest.tongdun.cn
com.tenwa.jianghd.url3=/bodyguard/apply/v4.3
com.tenwa.jianghd.partner_code=apgj
com.tenwa.jianghd.partner_key=3a7be6a6d73c48b18f083ddf8d399538
com.tenwa.jianghd.app_name=apgj_web
com.tenwa.jianghd.biz_code=OnLine
com.tenwa.jianghd.encode=UTF-8

View File

@ -8,6 +8,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jbo.com.tenwa.lease.comm.LB_TELONLINE;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
@ -20,6 +22,10 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import com.alibaba.fastjson.JSON;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.BizObjectManager;
import com.amarsoft.are.jbo.JBOException;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
@ -27,49 +33,70 @@ import com.tenwa.comm.util.jboutil.DataOperatorUtil;
public class OnlineClient {
private static String partner_code = "apgj";
private static String URI_SEND_SMS = "https://apitest.tongdun.cn/bodyguard/apply/v4.3";
private static String ENCODING = "UTF-8";
private static String partner_key = "3a7be6a6d73c48b18f083ddf8d399538";
private static String app_name = "apgj_web";
private static String biz_code = "OnLine";
private static String partner_code = TelOnLineConfigure.get("com.tenwa.jianghd.partner_code");
private static String url1 = TelOnLineConfigure.get("com.tenwa.jianghd.url1");
private static String url2 = TelOnLineConfigure.get("com.tenwa.jianghd.url2");
private static String url3 = TelOnLineConfigure.get("com.tenwa.jianghd.url3");
// private static String URI_SEND_SMS = "https://apitest.tongdun.cn/bodyguard/apply/v4.3";
private static String ENCODING =TelOnLineConfigure.get("com.tenwa.jianghd.encode");
private static String partner_key = TelOnLineConfigure.get("com.tenwa.jianghd.partner_key");
private static String app_name =TelOnLineConfigure.get("com.tenwa.jianghd.app_name");
private static String biz_code = TelOnLineConfigure.get("com.tenwa.jianghd.biz_code");
private String flowunid;
private String projectId;
private String onLineId;
public static void main(String[] org0) throws ClientProtocolException, IOException, URISyntaxException{
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(getUri());
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("account_mobile", "18721658364"));
nvps.add(new BasicNameValuePair("biz_code", biz_code));
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
CloseableHttpResponse response2 = httpclient.execute(httpPost);
try {
System.out.println(response2.getStatusLine().getStatusCode());
HttpEntity entity2 = response2.getEntity();
String ss = EntityUtils.toString(entity2);
System.out.println(ss);
EntityUtils.consume(entity2);
} finally {
response2.close();
}
System.out.println(partner_code+","+url1);
//
// CloseableHttpClient httpclient = HttpClients.createDefault();
//
// HttpPost httpPost = new HttpPost(getUri());
// List <NameValuePair> nvps = new ArrayList <NameValuePair>();
// //WF2018081112414717786099
// nvps.add(new BasicNameValuePair("account_mobile", "13000000000"));
// nvps.add(new BasicNameValuePair("biz_code", biz_code));
//// nvps.add(new BasicNameValuePair("id", "WF2018081112414717786099"));
//// nvps.add(new BasicNameValuePair("invoke_type", "RETRY"));
// httpPost.setEntity(new UrlEncodedFormEntity(nvps));
//
// CloseableHttpResponse response2 = httpclient.execute(httpPost);
//
// try {
// System.out.println(response2.getStatusLine().getStatusCode());
// HttpEntity entity2 = response2.getEntity();
// String ss = EntityUtils.toString(entity2);
// Map mapTypes = JSON.parseObject(ss);
// System.out.println(mapTypes);
// EntityUtils.consume(entity2);
// } finally {
// response2.close();
// }
}
public static URI getUri() throws URISyntaxException{
URI uri = URIUtils.createURI("https", "apitest.tongdun.cn", -1, "/bodyguard/apply/v4.3",
"partner_code=apgj&partner_key=3a7be6a6d73c48b18f083ddf8d399538&app_name=apgj_web", null);
URI uri = URIUtils.createURI(url1, url2, -1, url3,
"partner_code="+partner_code+"&partner_key="+partner_key+"&app_name="+app_name, null);
return uri;
}
public String postOnLine(String phone) throws URISyntaxException, ClientProtocolException, IOException{
public String postOnLine(String phone,String nextService,String onLineId) throws Exception{
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(getUri());
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("account_mobile", phone));
nvps.add(new BasicNameValuePair("biz_code", biz_code));
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
//重试
if("RETRY".equals(nextService)){
nvps.add(new BasicNameValuePair("invoke_type", nextService));
nvps.add(new BasicNameValuePair("id", onLineId));//进件id
}else{
//首发
nvps.add(new BasicNameValuePair("account_mobile", phone));
}
httpPost.setEntity(new UrlEncodedFormEntity(nvps,ENCODING));
CloseableHttpResponse response2 = httpclient.execute(httpPost);
try {
@ -77,17 +104,63 @@ public class OnlineClient {
System.out.println(statusCode);
if(statusCode==200){
HttpEntity entity2 = response2.getEntity();
String ss = EntityUtils.toString(entity2);
System.out.println(ss);
return ss;
String str = EntityUtils.toString(entity2);
System.out.println(str);
return str;
}else{
return "ÇëÇóÊý¾Ýʧ°Ü¡£";
throw new Exception("请求数据失败");
}
// EntityUtils.consume(entity2);
} finally {
response2.close();
}
}
//单条重发
public String getTelOnLineReTry(JBOTransaction tx){
try {
String jsonStr = postOnLine("","RETRY",onLineId);
Map mapTypes = JSON.parseObject(jsonStr);
boolean success = (boolean)(mapTypes.get("success"));
if(success){
String onLineId = mapTypes.get("id").toString();
String result_desc = mapTypes.get("result_desc").toString();
Map MobileDuration = JSON.parseObject(JSON.parseObject(JSON.parseObject(result_desc).get("AUTHENTICATION_INFOQUERY").toString()).get("MobileDuration").toString());
Object mobile_online_time_info = "";
Object mobile_online_time_consistence = "";
if(MobileDuration.get("error_info")==null){
mobile_online_time_info = MobileDuration.get("mobile_online_time_info");
mobile_online_time_consistence = MobileDuration.get("mobile_online_time_consistence");
}
//失败特有的参数
Object nextService = mapTypes.get("nextService");
Object reason_code = mapTypes.get("reason_code");
Object reason_desc = mapTypes.get("reason_desc");
//更新需要重发的数据
JBOFactory.getBizObjectManager(LB_TELONLINE.CLASS_NAME, tx).createQuery("update O set success='"+success+"',result_desc='"+result_desc+"',"
+ "mobile_online_time_info='"+mobile_online_time_info+"',mobile_online_time_consistence='"+mobile_online_time_consistence+"',"
+ "nextService='"+nextService+"',reason_code='"+reason_code+"',reason_desc='"+reason_desc+"' where online_id=:id")
.setParameter("id", onLineId).executeUpdate();
}else{
Object reason_code = mapTypes.get("reason_code");
Object reason_desc = mapTypes.get("reason_desc");
//更新需要重发的数据
JBOFactory.getBizObjectManager(LB_TELONLINE.CLASS_NAME, tx).createQuery("update O set success='"+success+"'"
+ ",reason_code='"+reason_code+"',reason_desc='"+reason_desc+"' where online_id=:id")
.setParameter("id", onLineId).executeUpdate();
}
tx.commit();
} catch (Exception e) {
e.printStackTrace();
try {
tx.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
}
return "调用数据失败";
}
return "true";
}
//业务申请流程中获取包括 承租人共同申请人担保人的手机号
public String getTelOnLine(JBOTransaction tx){
String sql = "select certid,FULLNAME as name,MOBILE as phone,'assuror' as custtype,'担保人' as typename from LB_GUARANTEE_UNIT_TEMP where flowunid='"+flowunid+"' and CERTTYPE='Ind01' "
@ -97,15 +170,54 @@ public class OnlineClient {
List<Map<String,String>> ds = DataOperatorUtil.getDataBySql(tx, sql, null);
if(ds.size()>0){
for (int i = 0; i < ds.size(); i++) {
String name = ds.get(i).get("NAME");
String phone = ds.get(i).get("PHONE");
String jsonStr = postOnLine(phone);
String certid = ds.get(i).get("certid");
String name = ds.get(i).get("name");
String phone = ds.get(i).get("phone");
BizObjectManager ltbom = JBOFactory.getBizObjectManager(LB_TELONLINE.CLASS_NAME, tx);
BizObject lton = ltbom.createQuery("PERSON_ID=:PERSON_ID").setParameter(LB_TELONLINE.PERSON_ID, certid).getSingleResult(true);
Map mapTypes =null;
//1.不存在则新增
if(lton==null){
String jsonStr = postOnLine(phone,"","");
mapTypes = JSON.parseObject(jsonStr);
lton = ltbom.newObject();
lton.setAttributeValue(LB_TELONLINE.PROJECT_ID, projectId);
lton.setAttributeValue(LB_TELONLINE.PERSON_ID, certid);
lton.setAttributeValue(LB_TELONLINE.USER_NAME, name);
lton.setAttributeValue(LB_TELONLINE.TELEPHONE, phone);
}else{
//2.存在则重发
String jsonStr = postOnLine(phone,lton.getAttribute(LB_TELONLINE.nextService).getString(),lton.getAttribute(LB_TELONLINE.online_id).getString());
mapTypes = JSON.parseObject(jsonStr);
}
//2.1并根据响应回来的结果更新数据
lton.setAttributeValue(LB_TELONLINE.success, mapTypes.get("success"));
if("true".equals(mapTypes.get("success").toString())){
lton.setAttributeValue(LB_TELONLINE.online_id, mapTypes.get("id"));
lton.setAttributeValue(LB_TELONLINE.result_desc, mapTypes.get("result_desc"));
String result_desc = mapTypes.get("result_desc").toString();
Map MobileDuration = JSON.parseObject(JSON.parseObject(JSON.parseObject(result_desc).get("AUTHENTICATION_INFOQUERY").toString()).get("MobileDuration").toString());
if(MobileDuration.get("error_info")==null){
lton.setAttributeValue(LB_TELONLINE.mobile_online_time_info, MobileDuration.get("mobile_online_time_info"));
lton.setAttributeValue(LB_TELONLINE.mobile_online_time_consistence, MobileDuration.get("mobile_online_time_consistence"));
}
//失败特有的参数
lton.setAttributeValue(LB_TELONLINE.nextService, mapTypes.get("nextService"));
}
lton.setAttributeValue(LB_TELONLINE.reason_code, mapTypes.get("reason_code"));
lton.setAttributeValue(LB_TELONLINE.reason_desc, mapTypes.get("reason_desc"));
ltbom.saveObject(lton);
}
tx.commit();
}
} catch (Exception e) {
try {
tx.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
return e.getMessage();
}
return "true";
}
@ -118,6 +230,18 @@ public class OnlineClient {
public void setFlowunid(String flowunid) {
this.flowunid = flowunid;
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getOnLineId() {
return onLineId;
}
public void setOnLineId(String onLineId) {
this.onLineId = onLineId;
}

View File

@ -0,0 +1,40 @@
package com.tenwa.lease.flow.project.validate;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import com.amarsoft.are.ARE;
public class TelOnLineConfigure {
private static Map<String, String> attributes;
public static void load() {
attributes = new ConcurrentHashMap<String, String>();
Properties prop = new Properties();
try {
prop.load(TelOnLineConfigure.class.getResourceAsStream("/telonline.properties"));
for(Entry<Object, Object> entry : prop.entrySet()) {
if(entry.getKey() == null || entry.getValue() == null) {
continue;
}
attributes.put(entry.getKey().toString(), entry.getValue().toString());
}
} catch (IOException e) {
e.printStackTrace();
ARE.getLog().error("init GPSConfigure info failed");
}
ARE.getLog().info("init GPSConfigure info success");
}
public static void destroy() {
if(attributes != null) attributes.clear();
}
public static String get(String propName) {
if(attributes == null) load();
return attributes.get(propName);
}
}