Java项目中调用第三方接口的方式有:
https://blog.csdn.net/riemann_/article/details/90539829
接口
restful类型接口
接口工具类
package com.landray.kmss.km.imeeting.util; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import java.util.Map; /** * 会议接口工具 * SpringBoot-RestTemplate方式调用第三方http接口的方式
* * @author CRJ */ public class BusInterfaceUtil { public static String url="http://bkpaas4.aac.com/api/c/self-service-api/create_meeting_webex_version_test/"; /** * 会议接口地址 */ /** * 调用总线接口服务 * * @param url * * @param map * 请求报文 * @return 响应报文 */ public static String sendPost(String url, Map map){ // 定义header对象 HttpHeaders headers = new HttpHeaders(); // 定义http请求实体对象 HttpEntity< Map<String,Object> > entity = new HttpEntity< Map<String,Object>>(map,headers); // 发送请求 RestTemplate template = new RestTemplate(); ResponseEntity<Map> exchange = template.exchange(url, HttpMethod.POST, entity, Map.class); return exchange.getBody().toString(); } }
实现类:
package com.landray.kmss.km.imeeting.service.spring; import com.landray.kmss.common.model.IBaseModel; import com.landray.kmss.km.imeeting.model.KmImeetingDevice; import com.landray.kmss.km.imeeting.model.KmImeetingMain; import com.landray.kmss.km.imeeting.util.BusInterfaceUtil; import com.landray.kmss.sys.lbpm.engine.manager.event.EventExecutionContext; import com.landray.kmss.sys.lbpm.engine.manager.event.IEventListener; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /*CRJ 流程结束事件监听 流程结束后调用接口创建会议 */ public class KmIMeetingCreateListener implements IEventListener { public void handleEvent(EventExecutionContext execution, String parameter) throws Exception { String url="http://bkpaas4.aac.com/api/c/self-service-api/create_meeting_webex_version_test/"; IBaseModel mainModel = execution.getMainModel(); KmImeetingMain kmImeetingMain=(KmImeetingMain)mainModel; Double fdHoldDuration=kmImeetingMain.getFdHoldDuration();//会议时长(毫秒) int durationd=(int)(fdHoldDuration/1000/60);//会议时长(分) String duration ="" + durationd; Date fdHoldDate=kmImeetingMain.getFdHoldDate();//开始时间 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd\'T\'HH:mm:ss"); String start_time = format.format(fdHoldDate); String type="1";//会议类型 未确定传什么值 List<KmImeetingDevice> kmImeetingDevices=kmImeetingMain.getKmImeetingDevices();//会议资源 if(kmImeetingDevices!=null&&kmImeetingDevices.size()>0){ boolean phone = kmImeetingDevices.contains("电话"); boolean Desktop = kmImeetingDevices.contains("桌面共享"); System.out.println("phone:"+phone); System.out.println("Desktop:"+Desktop); if(phone){ type="1"; }if(Desktop){ type="2"; }if(phone||Desktop){ type="3"; } }else{ return;//不包含电话或桌面共享则不调用接口 } //会议编号 //参加人数 String has_external_user="";//是否有外部人员参加 String external_user="";//外部参加人 System.out.println("kmImeetingMain.getDocChoiceOAPerson():"+kmImeetingMain.getDocChoiceOAPerson()); if(kmImeetingDevices!=null){ if(kmImeetingMain.getDocChoiceOAPerson().equals("YES")){ external_user=kmImeetingMain.getFdOtherAttendPerson(); has_external_user="1"; }else{ has_external_user="0"; } } //参加人 String has_senior_director="";//是否有高级总监 String senior_director="";//高级总监 if(kmImeetingDevices!=null){ if(kmImeetingMain.getDocChoiceDirector().equals("YES")){ for(int i=0;i<kmImeetingMain.getDocDirectors().size();i++){ senior_director=kmImeetingMain.getDocDirectors().get(i).getFdName()+";"+senior_director; } has_senior_director="1"; }else{ has_senior_director="0"; } } String has_it_duty="0";//是否需要IT值守 String it_duty_location="";//值守地点 if(kmImeetingMain.getDocChoiceDirector().equals("YES")){ if(kmImeetingMain.getDocChoiceGuard().equals("YES")){ has_it_duty="1"; it_duty_location=kmImeetingMain.getDocGuardLocation(); }else{ has_it_duty="0"; } }
//需要传过去的值 Map<String,Object> map = new HashMap<String,Object>();; map.put("bk_app_code","meeting-resource"); map.put("bk_app_secret","bcf15e2d-86c8-45d7-b796-e5f178957836"); map.put("bk_username","BPM"); map.put("bpm_no",kmImeetingMain.getFdMeetingNum()); //会议编号 map.put("applicant",kmImeetingMain.getDocCreator().getFdName());//会议申请人docCreatorName map.put("topic",kmImeetingMain.getDocSubject());//会议主题 map.put("email",kmImeetingMain.getDocEmail());//申请人邮件 map.put("start_time",start_time);//开始时间 map.put("duration",duration);//会议时长(分) map.put("type",type);//会议类别 map.put("participant_number",kmImeetingMain.getFdAttendNum()); map.put("has_external_user",has_external_user);//是否有外部人员参加 map.put("external_user",external_user);//外部参加人 map.put("has_senior_director",has_senior_director);//是否有高级总监 map.put("senior_director",senior_director);//高级总监 map.put("has_it_duty",has_it_duty);//是否需要IT值守 map.put("it_duty_location",it_duty_location);//it人员 String result=BusInterfaceUtil.sendPost(BusInterfaceUtil.url,map); System.out.println("----------------------------"); System.out.println(result); System.out.println("----------------------------"); throw new Exception("111"); } }
https://blog.csdn.net/forMelo/article/details/79016952
https://www.cnblogs.com/huangwentian/p/6931514.html
webservice接口