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-读写文件的方式

    open(path, flag[, encoding][, errors]) path:要打开文件的路径 flag:打开方式 r 以只读的方式打开文件,文件的描述符放在文件的开头 rb 以二进制格式打 ...

  2. ethereum(以太坊)(一)

    从这周开始,开始学习以太坊开发--solidity,开始决定往区块链方向发展,毕竟区块链技术应用广泛.一开始接触solidity开发语言不太习惯,毕竟一直在学习python语法,有很多都不能接受.有难 ...

  3. 【php】关于trim,rtrim,ltrim,substr 的字符串切割导致 json,_encode无法 识别数据的问题

    示例 <?php $a = rtrim('南宁 .',' .'); echo $a; //输出 南�� echo json_encode($a); //输出空白 $b = ['name'=> ...

  4. yii2 url 美化参数

    所谓的url参数美化就是将冗长的字符串 进行正则替换 yii2 框架的url参数美化完成需要完成两个阶段 第一个阶段分apache和nginx 两种的配置 apache :1.1 必须开启rewrit ...

  5. elasticsearch 5.x 系列之二 线程池的设置

    1,概述 每个Elasticsearch节点内部都维护着多个线程池,如index.search.get.bulk等,用户可以修改线程池的类型和大小,以及其他的比如reflesh, flush,warm ...

  6. C++ 无符号整型和整型的区别

    在Win 7系统中,short 表示的范围为 - 32767到 32767,而无符号的short表示的范围为0 到 65535,其他类型的同理可推导出来,当然,仅当数字不为负的时候才使用无符号类型. ...

  7. python-10多进程

    1-多进程(multiprocessing), 1个父进程可以有多少子进程 1.1下面的例子演示了启动一个子进程并等待其结束 from multiprocessing import Process i ...

  8. requests--etree--xpath

    # -*- coding: cp936 -*- import requests from lxml import etree url = 'https://weibo.cn/pub/' html = ...

  9. 1008: [HNOI2008]越狱(计数问题)

    1008: [HNOI2008]越狱 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 11361  Solved: 4914[Submit][Status ...

  10. Android学习记录(1)—Android中XML文件的序列化生成与解析

    xml文件是非常常用的,在android中json和xml是非常常用的两种封装数据的形式,从服务器中获取数据也经常是这两种形式的,所以学会生成和解析xml和json是非常有用的,json相对来说是比较 ...