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. Python文件IO(普通文件读写)

    ## 打开一个文件 - fileobj = open(filename, mode) 其中: fileobj是open()返回的文件对象 filename是该文件的字符串名 mode是指明文件类型和操 ...

  2. 守护进程,进程安全,IPC进程间通讯,生产者消费者模型

    1.守护进程(了解)2.进程安全(*****) 互斥锁 抢票案例3.IPC进程间通讯 manager queue(*****)4.生产者消费者模型 守护进程 指的也是一个进程,可以守护着另一个进程 一 ...

  3. [CodeForces940E]Cashback(set+DP)

    Description Since you are the best Wraith King, Nizhniy Magazin «Mir» at the centre of Vinnytsia is ...

  4. 适配IE8+等浏览器的适配播放插件

    function myBrowser(){ var userAgent = navigator.userAgent; //ȡ���������userAgent�ַ� var isOpera = us ...

  5. PHP.13-日历类实现

    日历类实现 1.输出星期 calendar.class.php <?php class Calendar{ function out(){//输出表格 echo '<table align ...

  6. Best Practices in JavaScript

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

  7. MVC WebAPI 的基本使用

    1.什么是WebAPI Web API是网络应用程序接口.包含了广泛的功能,网络应用通过API接口,可以实现存储服务.消息服务.计算服务等能力,利用这些能力可以进行开发出强大功能的web应用. 它可以 ...

  8. 图的深度优先遍历&广度优先遍历

    1.什么是图的搜索? 指从一个指定顶点可以到达哪些顶点   2.无向完全图和有向完全图 将具有n(n-1)/2条边的无向图称为无向完全图(完全图就是任意两个顶点都存在边). 将具有n(n-1)条边的有 ...

  9. 每天一个Linux命令(2):shutdown命令

    shutdown命令是系统关机命令.shutdown指令可以关闭所有程序,并依用户的需要,进行重新开机或关机的动作. 语法 shutdown(选项)(参数) 选项 -c:取消已经在进行的 shutdo ...

  10. selenium获取浏览器控制台日志

    public void logsTest(){ WebDriver driver = null; try { System.setProperty("webdriver.chrome.dri ...