HTTP Basic 机制
package com.enation.app.shop.component.payment.plugin.cod; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import net.sf.json.JSONObject; import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException; import com.enation.framework.util.EncryptionUtil;
import com.enation.framework.util.JsonMessageUtil; import sun.misc.BASE64Encoder; public class CodUtils {
public static String getToken(){
String getTokenUrl = "https://api.homecredit.ru/oauth/token?grant_type=client_credentials";
HttpClient httpclient=new DefaultHttpClient();
HttpPost request = new HttpPost(getTokenUrl);
request.addHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
String client_credentials = "trade_ease:trade_ease_secret";
sun.misc.BASE64Encoder base64Encode = new BASE64Encoder();
String str = base64Encode.encode(client_credentials.getBytes());
System.out.println(str);
request.addHeader("Authorization","Basic "+str);
HttpResponse response;
try {
response = httpclient.execute(request);
//根据返回码判断请求是否成功
System.out.println(response.getStatusLine().getStatusCode());
if(response.getStatusLine().getStatusCode()==200){
String tokenJson = EntityUtils.toString(response.getEntity());
System.out.println(tokenJson);
JSONObject getToken = JSONObject.fromObject(tokenJson);
String access_token = getToken.getString("access_token");
System.out.println(access_token);
return access_token;
}else {
System.out.println(EntityUtils.toString(response.getEntity()));
return "";
}
} catch (ClientProtocolException e) {
e.printStackTrace();
return "";
} catch (IOException e) {
e.printStackTrace();
return "";
}
} public static void main(String[] args) throws JSONException {
String lastName = "篮球6";
String lastNum = lastName.replaceAll("[^0-9]", "");
String myName = lastName.split(lastNum)[0];
System.out.println(myName);
String uri = EncryptionUtil
.authCode(
"DUdFR1gcGUURFkgEXgJNXwxcQw1eQRpQC10aUQ1IGkIAUF5FBnpYQRIACg1VERhXTVZf",
"DECODE");
System.out.println(uri);
/*org.json.JSONObject json=new org.json.JSONObject();
org.json.JSONArray jsonMembers = new org.json.JSONArray();
org.json.JSONObject member1 = new org.json.JSONObject();
try {
member1.put("loginname", "zhangfan");
member1.put("password", "userpass");
member1.put("email","10371443@qq.com");
member1.put("sign_date", "2007-06-12");
jsonMembers.put(member1);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} org.json.JSONObject member2 = new org.json.JSONObject();
try {
member2.put("loginname", "zf");
member2.put("password", "userpass");
member2.put("email","8223939@qq.com");
member2.put("sign_date", "2008-07-16");
jsonMembers.put(member2);
json.put("users", jsonMembers);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
org.json.JSONArray phone = new org.json.JSONArray();
phone.put("13355555555");
//json.
*/
org.json.JSONObject json=new org.json.JSONObject(); Map <String, String> totalPrice = new HashMap <String, String>();
totalPrice.put("amount", "50");
totalPrice.put("currency", "USD"); org.json.JSONArray items = new org.json.JSONArray();
org.json.JSONObject goods = new org.json.JSONObject();
goods.put("name", "YangXinYuan Mens Fashion Long sleeved shirt");
goods.put("quantity","1");
goods.put("seller","trade_ease_seller");
goods.put("itemPrice",totalPrice);
goods.put("category","TRADE_EASE_TEST_CATEGORY");
goods.put("weight","0.2kg");
items.put(goods); json.put("items",items);
json.put("totalPrice", totalPrice);
json.put("shippingCompanyId", "SPSR");
//System.out.println(json.toString()); List<List> a = new ArrayList();
List b = new ArrayList();
b.add("1");
b.add("1战队");
a.add(b); List c = new ArrayList();
c.add("1");
c.add("2战队");
a.add(c); String listStr = net.sf.json.JSONArray.fromObject(a).toString();
//System.out.println(listStr); List<Map> listMap = new ArrayList(); Map dfdfMap = new HashMap();
dfdfMap.put("名词", "1");
dfdfMap.put("战队id", "123");
dfdfMap.put("战队名字", "1也来"); Map dfdfMap2 = new HashMap();
dfdfMap2.put("名词", "2");
dfdfMap2.put("战队id", "124");
dfdfMap2.put("战队名字", "11也地方"); Map dfdfMap3 = new HashMap();
dfdfMap3.put("名词", "3");
dfdfMap3.put("战队id", "125");
dfdfMap3.put("战队名字", "1fff地方"); listMap.add(dfdfMap);
listMap.add(dfdfMap2);
listMap.add(dfdfMap3);
String listStr2 = net.sf.json.JSONArray.fromObject(listMap).toString();
System.out.println(listStr2);
//a.add("df"); } }
HTTP 验证
验证采用 HTTP Basic 机制,即 HTTP Header(头)里加一个字段(Key/Value对):
Authorization: Basic base64_auth_string
其中 base64_auth_string 的生成算法为:base64(appKey:masterSecret)
即,对 appKey 加上冒号,加上 masterSecret 拼装起来的字符串,再做 base64 转换。
HTTP Basic 机制的更多相关文章
- RESTFUL API 安全设计指南
RESTFUL API 安全设计指南 xxlegend · 2015/10/18 15:08 0x01 REST API 简介 REST的全称是REpresentational State Trans ...
- REST API 安全设计指南
0x01 REST API 简介 REST的全称是REpresentational State Transfer,表示表述性无状态传输,无需session,所以每次请求都得带上身份认证信息.rest是 ...
- Nginx详解以及LNMP的搭建
v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...
- nginx常用模块
Nginx模块介绍 核心模块:core module 标准模块:stand modules HTTP modules: Standard HTTP modules Optional HTTP modu ...
- nginx配置2
第四节 nginx 配置文件 1 keepalive_timeout 65; 设定保存长久连接时长 0代表禁止, 若不设置默认是75s 2keepalive_requests nu; 在一 ...
- (转)nginx 常用模块整理
原文:http://blog.51cto.com/arm2012/1977090 1. 性能相关配置 worker_processes number | auto: worker进程的数量:通常应该为 ...
- nginx 模块介绍
nginx模块在编译文件下的odjs目录下 cat 查看ngx_modules.c文件 可以看到一些基本extern模块 常用标准模块 1. 性能相关配置 worker_processes numbe ...
- Nginx模块详解
Nginx模块介绍 核心模块:core module 标准模块: HTTP modules: Standard HTTP modules Optional HTTP modules Mail modu ...
- nginx全局配置和性能优化
nginx目录结构和命令 1.ls /apps/nginx/: html是测试页,sbin是主程序 2.ls /apps/nginx/sbin/: nginx 只有一个程序文件 3. ...
随机推荐
- Swoole 创建服务
1: 创建TCP 服务器 $serv = new swoole_server(‘127.0.0.1’,9501); 2:创建UDP服务器 $serv = new swoole_server('127 ...
- php 微信公众号图文消息回复的实现 与access_token
//代码如下 <?phpclass IndexAction extends Action { public function __construct(){ } public function i ...
- sql语句(Oracle和sqlserver)
查询表的首句:(Oracle) select * from (select a.*, rownum as rn from tab_name a order by col )where rn = 1 o ...
- bedtools
- E - Nature Reserve CodeForces - 1059D
传送门 There is a forest that we model as a plane and live nn rare animals. Animal number iihas its lai ...
- 菜鸟学Linux - Tarball安装的一般步骤
所谓的Tarball软件,实际上指的是从网络上下载到的源码包.通常是以.tar.gz和tar.bz2结尾.至于gz和bz2的区别在于压缩算法的不同(bz2的压缩效果好像好一些).源码包下载完成后,需要 ...
- 剑指offer题目练习一
看见了一道二维数组找数的题,已排好序的数组(从左至右从上到下,都是由小变大的)让找数,瞬间就出思路了,并没有必要去看他的解释,两次二分就搞定了. #include<cstdio> #inc ...
- Unity Occlusion Culling 遮挡剔除研究
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/52684127 作者:car ...
- SpringMVC---springMVC配置文件(springweb.xml)简介
再web.xml中设置HTTP请求的中央调度处理器DispatcherServlet时,会指定SpringMVC配置文件,这里取名springweb.xml是因设置DispatcherServlet时 ...
- vue-i18n vue-cli项目中实现国际化 多语言切换功能 一
vue-cli项目中引入vue-i18n 安装: npm install vue-i18n可参考vue-i18n官网文档 main.js中引入: import Vue from 'vue' impor ...