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

辽icp备鞍山公司中企动力提供网站建设自己做网站需要什么条件

辽icp备鞍山公司中企动力提供网站建设,自己做网站需要什么条件,网页界面设计特点,网页制作的论文目录 前言 一、黄金段位接口交互 二、钻石段位接口交互设计 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://www.shuangfujiaoyu.com/news/50310.html

相关文章:

  • 国外设计网站排名谷歌seo是什么
  • 云教育科技网站建设2020最近的新闻大事10条
  • 上海实时新闻seo关键词推广
  • 校园二手用品网站建设的项目章程2345导航网址
  • 企业网站建设参考文献怎么制作网页里面的内容
  • 网站管理助手 ftpseo推广和百度推广的区别
  • 网站seo优化要懂得做微调百度平台商家联系方式
  • 如何重新做公司网站设计网站logo
  • 绿色国外网站肇庆网络推广
  • 网站验证码是如何做的必应搜索推广
  • 网站开发需要掌握的哪些开发软件常见的网络直接营销有哪些
  • 幼儿园网站模板怎么做的百度首页精简版
  • 做商城网站需要在北京注册公司吗建立一个企业网站需要多少钱
  • 尚一网常德论坛seo是什么意思
  • 肇庆 网站建设竞价推广员月挣多少
  • 域名备案后怎样做网站湖北seo服务
  • 如何做一张网站平面效果图百度关键词的费用是多少
  • 网站制作套餐seo排名点击手机
  • go搭建网站通州优化公司
  • 整站seo排名公司潍坊今日头条新闻
  • 网站上传到虚拟服务器啥是网络推广
  • 市委宣传部全称seo外包公司专家
  • 网上购物商城网站建设河北百度seo关键词
  • 怎么做网站安全运维有哪些免费推广网站
  • 网站h1标签怎么做推广app接单网
  • 微博推广会被别人看出来吗谷歌seo推广
  • 网站做跳转在后天那个文件里做今日国内新闻最新消息10条
  • 货源一件代发从哪里找整站优化包年
  • 怎么用记事本做钓鱼网站青岛网站设计公司哪家好
  • 手机做炫光图头像的网站乔拓云网微信小程序制作