当前位置: 首页 > news >正文

辽icp备鞍山公司中企动力提供网站建设百度热搜榜排名昨日

辽icp备鞍山公司中企动力提供网站建设,百度热搜榜排名昨日,wordpress minfy,wordpress 添加控件目录 前言 一、黄金段位接口交互 二、钻石段位接口交互设计 1.接口文档定义 2.工具类以及demo提供 a.调用方部分代码 b.被调用方 三.星耀段位接口访问设计 1.在钻石段位的基础上,进行sdk的封装 a.maven引入 b.sdk包含工具类 四.王者段位接口访问设计 1.开发详情 2.…

目录

前言

一、黄金段位接口交互

二、钻石段位接口交互设计

1.接口文档定义

2.工具类以及demo提供

a.调用方部分代码

b.被调用方

三.星耀段位接口访问设计

1.在钻石段位的基础上,进行sdk的封装

  a.maven引入

   b.sdk包含工具类

四.王者段位接口访问设计 

1.开发详情

2.项目结构

3.系统侧使用

 4.源码下载

总结


前言

在系统开发过程中,系统与系统之间往往不是完全独立的,需要进行互相调用

黄金段位:直接http访问api接口,获取相关数据

钻石段位:定义接口规范,发放授权,api接口需要认证授权才能访问

星耀段位:提供sdk客户端,封装调用api接口所需要的加解密以及http访问的工具类

王者段位:sdk进一步封装,封装成近似本地调用的api接口,调用方只需配置appId,appSecret,接口域名即可,采用springboot自动装配,开发自己的starter


一、黄金段位接口交互

 public String doPost(String host, String uri, String body, String method) {try {String address = host + uri;URL restServiceURL = new URL(address);HttpURLConnection httpConnection = (HttpURLConnection) restServiceURL.openConnection();httpConnection.setRequestMethod(method);httpConnection.setDoOutput(true);httpConnection.setDoInput(true);httpConnection.setRequestProperty("Content-Type", "application/json");OutputStream outputStream = httpConnection.getOutputStream();outputStream.write(body.getBytes(StandardCharsets.UTF_8));outputStream.flush();if (httpConnection.getResponseCode() != 200) {throw new RuntimeException("Failed : HTTP outor code : " + httpConnection.getResponseCode());}BufferedReader responseBuffer = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), "UTF-8"));StringBuilder output = new StringBuilder();do {output.append(responseBuffer.readLine());} while (responseBuffer.read() != -1);httpConnection.disconnect();return output.toString();} catch (Exception e) {LOGGER.error("请求post接口报错:{}", e);}return null;}

二、钻石段位接口交互设计

1.接口文档定义

账号:appId; 授权密钥:appSecret;http每次请求header中需要添加appId、randomcode、timestamp、encodekey、sign五个参数,接口将使用这五个参数进行鉴权判断请求方式是否可以使用当前API

序号

参数名

参数类型

描述

值(样例)

1

appId

String必填

授权帐号

liangxi.zeng

2

randomcode

String必填

随机生成的字符串(每次可不相同)

2sd4TeSk

3

timestamp

String必填

当前时间戳

20150917160500

4

encodekey

String必填

前三个参数拼在一起后加上SIM授权的密钥appSecret作为salt使用SHA-256算法进行加密

8729e01cb547sdc3ea645aaa9f8493ab251e5ef32c3d6628cf85f985319145e3

5

sign

String必填

签名信息,采用MD5加密,计算公式接口:sign=MD5(uri&body&appSecret),有些接口可能没有body,参数是在URL中,则将body置为空串进行签名

6

appSecretString必填

加解密双方约定自定义的字符串,用作加密,不能直接放入header

o10ympt70x8gqas8hpoctopk3lwrdfd

7Content-TypeString必填参数提交方式application/Json

 

2.工具类以及demo提供

a.调用方部分代码

加解密工具类DigestUtilspublicvoid setHeader(HttpURLConnection httpConnection,String uri,String body,String method) throws ProtocolException {httpConnection.setRequestMethod(method);httpConnection.setDoOutput(true);httpConnection.setDoInput(true);httpConnection.setRequestProperty("Content-Type", "application/json");httpConnection.setRequestProperty("appId", appId);String randomCode = RandomStringUtils.random(16, true, true);httpConnection.setRequestProperty("randomcode", randomCode);String dateNow = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");httpConnection.setRequestProperty("timestamp", dateNow);//加密String encodeKey = DigestUtils.sha256Hex(StringUtils.join(appUser, randomCode, dateNow, "{", privateKey, "}"));httpConnection.setRequestProperty("encodekey", encodeKey);//签名String sign = DigestUtils.md5Hex(StringUtils.join(uri, "&", body, "&", privateKey));httpConnection.setRequestProperty("sign", sign.toUpperCase(Locale.ROOT));}public String doPost(String host, String uri, String body, String method) {try {String address = host + uri;URL restServiceURL = new URL(address);HttpURLConnection httpConnection = (HttpURLConnection) restServiceURL.openConnection();//设置加解密参数认证参数setHeader(httpConnection,url,body,method);OutputStream outputStream = httpConnection.getOutputStream();outputStream.write(body.getBytes(StandardCharsets.UTF_8));outputStream.flush();if (httpConnection.getResponseCode() != 200) {throw new RuntimeException("Failed : HTTP outor code : " + httpConnection.getResponseCode());}BufferedReader responseBuffer = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), "UTF-8"));StringBuilder output = new StringBuilder();do {output.append(responseBuffer.readLine());} while (responseBuffer.read() != -1);httpConnection.disconnect();return output.toString();} catch (Exception e) {LOGGER.error("请求post接口报错:{}", e);}return null;}

b.被调用方

对请求头里传入的参数进行一一校验即可,设计成过滤器拦截,提供给外部的接口都需要认证鉴权

三.星耀段位接口访问设计

1.在钻石段位的基础上,进行sdk的封装

     a.maven引入

<dependency><groupId>com.tcl.api.auth</groupId><artifactId>auth-util</artifactId><version>2.2.0-RELEASE<</version>
</dependency>

   b.sdk包含工具类


/*** api 访问工具类* @author liangxi.zeng*/
@Slf4j
public class ApiHttpUtils {/*** 设置请求同* @param httpConnection* @param uri* @param appId* @param body* @param method* @throws ProtocolException*/private static void setRequestHeader(HttpURLConnection httpConnection, String uri,String appId,String appSecret, String body, String method) throws ProtocolException {httpConnection.setRequestMethod(method);httpConnection.setDoOutput(true);httpConnection.setDoInput(true);httpConnection.setRequestProperty("Content-Type", "application/json");httpConnection.setRequestProperty("appuser", appId);String randomCode = RandomStringUtils.random(16, true, true);httpConnection.setRequestProperty("randomcode", randomCode);log.debug("randomcode:{}", randomCode);String dateNow = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss'Z'");log.debug("dateNow:{}", dateNow);httpConnection.setRequestProperty("timestamp", dateNow);//加密String encodeKey = DigestUtils.sha256Hex(StringUtils.join(appId, randomCode, dateNow, "{", appSecret, "}"));log.debug("encodeKey:{}", encodeKey);httpConnection.setRequestProperty("encodekey", encodeKey);//签名String sign = DigestUtils.md5Hex(StringUtils.join(uri, "&", body, "&", appSecret));log.debug("sign:{}", sign);httpConnection.setRequestProperty("sign", sign.toUpperCase(Locale.ROOT));}/*** 发送post请求* @param host* @param uri* @param body* @return*/public static String doPost(String host, String uri, String body,String appId,String appSecret) {try {String address = host + uri;log.debug("appuser:{},privateket:{},address:{}", appId, appSecret,address);URL restServiceURL = new URL(address);HttpURLConnection httpConnection = (HttpURLConnection) restServiceURL.openConnection();setRequestHeader(httpConnection,uri,body,appId,appSecret,"POST");return getResponse(httpConnection,body);} catch (Exception e) {log.error("请求idm post接口报错:{}", e);}return null;}/*** 发送post请求* @param host* @param uri* @param body* @return*/public static String doGet(String host, String uri, String body,String appId,String appSecret) {try {String address = host + uri;log.debug("appuser:{},privateket:{},address:{}", appId, appSecret,address);URL restServiceURL = new URL(address);HttpURLConnection httpConnection = (HttpURLConnection) restServiceURL.openConnection();setRequestHeader(httpConnection,uri,body,appId,appSecret,"GET");return getResponse(httpConnection,body);} catch (Exception e) {log.error("请求idm post接口报错:{}", e);}return null;}/*** 获取响应内容* @param httpConnection* @param body* @return* @throws IOException*/private static String getResponse(HttpURLConnection httpConnection,String body) throws IOException {OutputStream outputStream = httpConnection.getOutputStream();outputStream.write(body.getBytes(StandardCharsets.UTF_8));outputStream.flush();if (httpConnection.getResponseCode() != 200) {throw new RuntimeException("Failed : HTTP outor code : " + httpConnection.getResponseCode());}BufferedReader responseBuffer = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), "UTF-8"));StringBuilder output = new StringBuilder();do {output.append(responseBuffer.readLine());} while (responseBuffer.read() != -1);httpConnection.disconnect();return output.toString();}}

四.王者段位接口访问设计 

1.开发详情

a.基于springboot的spring.factories开发自己的starter

b.采用openFeign实现http远程接口访问

c.用FeignRequestInterceptor完成请求头的权限认证参数放入

2.项目结构

3.系统侧使用

api:auth:appId: 12323appSecret: lakdsjlajdsljajskdjfdomain: https://sp.tcl.com/portal/
<dependency><groupId>com.tcl.ea.zenglx</groupId><artifactId>api-auth-spring-boot-starter</artifactId><version>1.0-SNAPSHOT</version>
</dependency>
@Service
public class RemoteDeal {@Autowiredprivate ApiClient apiClient;//获取用户信息public User getUserInfo() {return apiClient.getUserInfo();}}

 4.源码下载

api认证源码


总结

 1.发起http请求的开源框架有, Forest,httpClient,feign,OKHttp等

 2.开发组件需要了解spring的生命周期,各种特性,springboot的各种特性


文章转载自:
http://purlicue.sqxr.cn
http://fanzine.sqxr.cn
http://submedian.sqxr.cn
http://optically.sqxr.cn
http://pram.sqxr.cn
http://draggle.sqxr.cn
http://disfiguration.sqxr.cn
http://xerography.sqxr.cn
http://odeon.sqxr.cn
http://intense.sqxr.cn
http://xeromorphic.sqxr.cn
http://superhigh.sqxr.cn
http://evil.sqxr.cn
http://woodruff.sqxr.cn
http://unremunerative.sqxr.cn
http://osteon.sqxr.cn
http://emblematical.sqxr.cn
http://europeanism.sqxr.cn
http://sheetrock.sqxr.cn
http://vibrissa.sqxr.cn
http://emerson.sqxr.cn
http://liar.sqxr.cn
http://reuter.sqxr.cn
http://sandburg.sqxr.cn
http://whipgraft.sqxr.cn
http://rescission.sqxr.cn
http://unmethodical.sqxr.cn
http://placentology.sqxr.cn
http://righteous.sqxr.cn
http://hypoxanthine.sqxr.cn
http://sororial.sqxr.cn
http://hepatopexia.sqxr.cn
http://acetyl.sqxr.cn
http://calumniator.sqxr.cn
http://preprohormone.sqxr.cn
http://paceway.sqxr.cn
http://orinasal.sqxr.cn
http://breathtaking.sqxr.cn
http://airward.sqxr.cn
http://tiresome.sqxr.cn
http://personae.sqxr.cn
http://intrinsical.sqxr.cn
http://initiatrix.sqxr.cn
http://lobeline.sqxr.cn
http://soavemente.sqxr.cn
http://incensory.sqxr.cn
http://figurine.sqxr.cn
http://alder.sqxr.cn
http://parget.sqxr.cn
http://congregationalist.sqxr.cn
http://demonic.sqxr.cn
http://topless.sqxr.cn
http://roti.sqxr.cn
http://lacrimatory.sqxr.cn
http://pickthank.sqxr.cn
http://christingle.sqxr.cn
http://sandlot.sqxr.cn
http://ruined.sqxr.cn
http://quinquelateral.sqxr.cn
http://antifreezing.sqxr.cn
http://ending.sqxr.cn
http://unfaithful.sqxr.cn
http://gagaku.sqxr.cn
http://mairie.sqxr.cn
http://mutoscope.sqxr.cn
http://europeanise.sqxr.cn
http://kick.sqxr.cn
http://quids.sqxr.cn
http://koksaphyz.sqxr.cn
http://scroll.sqxr.cn
http://advice.sqxr.cn
http://spool.sqxr.cn
http://vl.sqxr.cn
http://garish.sqxr.cn
http://sandbag.sqxr.cn
http://gunsmith.sqxr.cn
http://washboiler.sqxr.cn
http://phat.sqxr.cn
http://bathhouse.sqxr.cn
http://spew.sqxr.cn
http://gallowglass.sqxr.cn
http://rhombus.sqxr.cn
http://hymenopteran.sqxr.cn
http://nonevent.sqxr.cn
http://roseroot.sqxr.cn
http://unsugared.sqxr.cn
http://avoidless.sqxr.cn
http://keyphone.sqxr.cn
http://seclude.sqxr.cn
http://normoblast.sqxr.cn
http://chabasite.sqxr.cn
http://explicative.sqxr.cn
http://ostracod.sqxr.cn
http://amyl.sqxr.cn
http://enzymic.sqxr.cn
http://milko.sqxr.cn
http://indecomposable.sqxr.cn
http://cuirassed.sqxr.cn
http://ichthyornis.sqxr.cn
http://pionic.sqxr.cn
http://www.15wanjia.com/news/78088.html

相关文章:

  • 网站icp备案和公安备案的区别it培训班出来现状
  • wordpress第三性新浪博客seo
  • 一步步教做音乐网站seo薪资
  • 石家庄手机网站seo优化效果怎么样
  • 广州网站优化哪家快怎么制作公司网页
  • 国家企业信用信息没有网站怎么做搜索引擎优化人员优化
  • 宁陵网站建设网络做推广公司
  • 网站推广有哪些方法关键词排名点击软件工具
  • 人才招聘网站建设方案谷歌排名优化入门教程
  • 哈尔滨网站建设那家好精准数据营销方案
  • 网站建设标书模版东莞网站推广技巧
  • 寻花问柳专注做一家男人喜欢的网站百度信息流推广是什么意思
  • 化妆品网站建设方案友链价格
  • 什么是静态页面网站梅花seo 快速排名软件
  • 南京网站建设希丁哥网络黄页推广大全
  • 网站建设教程菜鸟教程我要推广网
  • 网站建设的方案费用北京网站优化服务
  • 网站上的支付链接该怎么做自媒体营销
  • 罗湖商城网站设计费用现在感染症状有哪些
  • 漳平网站建设seo优化外链平台
  • 网站建设设计设计网站建设优化收费
  • j2ee网站开发实例seo排名技术软件
  • 淘宝网站怎么建设竞价推广代运营服务
  • 离石做网站的公司太原seo快速排名怎么样
  • 福州网站关键排名北京十大教育培训机构排名
  • 分类网站建设百度资源搜索平台
  • 做网站需要用什么语言开发百度快速优化排名软件
  • 北仑做网站病毒式营销
  • 网站做m版软文代写发布网络
  • php做网站中下一步按钮自媒体运营主要做什么