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 机制的更多相关文章

  1. RESTFUL API 安全设计指南

    RESTFUL API 安全设计指南 xxlegend · 2015/10/18 15:08 0x01 REST API 简介 REST的全称是REpresentational State Trans ...

  2. REST API 安全设计指南

    0x01 REST API 简介 REST的全称是REpresentational State Transfer,表示表述性无状态传输,无需session,所以每次请求都得带上身份认证信息.rest是 ...

  3. Nginx详解以及LNMP的搭建

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

  4. nginx常用模块

    Nginx模块介绍 核心模块:core module 标准模块:stand modules HTTP modules: Standard HTTP modules Optional HTTP modu ...

  5. nginx配置2

    第四节 nginx 配置文件 1 keepalive_timeout   65;  设定保存长久连接时长 0代表禁止, 若不设置默认是75s 2keepalive_requests   nu;  在一 ...

  6. (转)nginx 常用模块整理

    原文:http://blog.51cto.com/arm2012/1977090 1. 性能相关配置 worker_processes number | auto: worker进程的数量:通常应该为 ...

  7. nginx 模块介绍

    nginx模块在编译文件下的odjs目录下 cat 查看ngx_modules.c文件 可以看到一些基本extern模块 常用标准模块 1. 性能相关配置 worker_processes numbe ...

  8. Nginx模块详解

    Nginx模块介绍 核心模块:core module 标准模块: HTTP modules: Standard HTTP modules Optional HTTP modules Mail modu ...

  9. nginx全局配置和性能优化

    nginx目录结构和命令 1.ls /apps/nginx/:         html是测试页,sbin是主程序 2.ls /apps/nginx/sbin/:  nginx 只有一个程序文件 3. ...

随机推荐

  1. 获取父窗口元素或者获取iframe中的元素(相同域名下)

    jquery方法 在父窗口中获取iframe中的元素 //方法1 $("#iframe的ID").contents().find("iframe中的元素"); ...

  2. Django自带后台管理配置

    Django自带后台管理的配置 创建项目和应用 修改配置文件 数据库配置 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql' ...

  3. python pycharm2018开启debug模式

    为什么需要开启DEBUG模式1.如果开启了DEBUG模式,那么在代码中如果抛出了异常,在浏览器的页面中可以看到具体的错误信息,以及具体的错误代码位置,方便开发者调试.2.如果开启DEBUG模式,那么以 ...

  4. poj 2579 中位数问题 查找第K大的值

    题意:对列数X计算∣Xi – Xj∣组成新数列的中位数. 思路:双重二分搜索 对x排序 如果某数大于 mid+xi 说明在mid后面,这些数的个数小于 n/2 的话说明这个中位数 mid 太大 反之太 ...

  5. ElasticSearch 环境安装

    1)官网安装教程: http://www.elasticsearch.org/guide/reference/setup/installation/   2)简单安装: http://log.medc ...

  6. python基础之列表、元组和字典

    列表 列表定义:[]内以逗号分隔,按照索引,存放各种数据类型,每个位置代表一个元素 特性: 1.可存放多个值 2.可修改指定索引位置对应的值,可变 3.按照从左到右的顺序定义列表元素,下标从0开始顺序 ...

  7. Best Practices in JavaScript

    Some items you should konw : Graceful degradation : ensuring that your web pages still work without ...

  8. JavaScript 仿ios滑动选择器

    从git上找了一个,不过不是我想要的,更改了许多.到了我想要的效果: roller_selector_0_9.js 首先上js: "use strict"; /* * Author ...

  9. 剑指Offer - 九度1504 - 把数组排成最小的数

    剑指Offer - 九度1504 - 把数组排成最小的数2014-02-06 00:19 题目描述: 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输 ...

  10. 命名空间“System.Web.Http”中不存在类型或命名空间名称“Description”(是否缺少程序集引用?)

    solution: Set "Copy Local : True" in properties for References\System.Web.Http   在http://s ...