Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
1632dfd2
提交
1632dfd2
authored
12月 27, 2020
作者:
wudepeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
paypal
上级
2942fc0c
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
73 行增加
和
7 行删除
+73
-7
pom.xml
pom.xml
+12
-0
PaypalConfig.java
...ain/java/com/example/afrishop_v3/config/PaypalConfig.java
+22
-7
PayPalUtil.java
src/main/java/com/example/afrishop_v3/util/PayPalUtil.java
+39
-0
没有找到文件。
pom.xml
浏览文件 @
1632dfd2
...
@@ -31,6 +31,12 @@
...
@@ -31,6 +31,12 @@
</dependencyManagement>
</dependencyManagement>
<dependencies>
<dependencies>
<dependency>
<groupId>
com.squareup.okhttp
</groupId>
<artifactId>
okhttp
</artifactId>
<version>
2.2.0
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-gcp-starter-vision
</artifactId>
<artifactId>
spring-cloud-gcp-starter-vision
</artifactId>
...
@@ -269,6 +275,12 @@
...
@@ -269,6 +275,12 @@
<artifactId>
junit
</artifactId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.testng
</groupId>
<artifactId>
testng
</artifactId>
<version>
RELEASE
</version>
<scope>
compile
</scope>
</dependency>
<!--发邮件 END-->
<!--发邮件 END-->
</dependencies>
</dependencies>
...
...
src/main/java/com/example/afrishop_v3/config/PaypalConfig.java
浏览文件 @
1632dfd2
package
com
.
example
.
afrishop_v3
.
config
;
package
com
.
example
.
afrishop_v3
.
config
;
import
com.example.afrishop_v3.util.PayPalUtil
;
import
com.paypal.base.codec.binary.Base64
;
import
com.paypal.base.rest.APIContext
;
import
com.paypal.base.rest.APIContext
;
import
com.paypal.base.rest.OAuthTokenCredential
;
import
com.paypal.base.rest.OAuthTokenCredential
;
import
com.paypal.base.rest.PayPalRESTException
;
import
com.paypal.base.rest.PayPalRESTException
;
import
com.squareup.okhttp.*
;
import
net.sf.json.JSONObject
;
import
org.apache.commons.lang3.builder.ToStringExclude
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.*
;
import
org.springframework.context.annotation.Configuration
;
import
org.testng.annotations.Test
;
import
org.springframework.context.annotation.Primary
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.*
;
@Configuration
@Configuration
public
class
PaypalConfig
{
public
class
PaypalConfig
{
...
@@ -23,6 +33,8 @@ public class PaypalConfig {
...
@@ -23,6 +33,8 @@ public class PaypalConfig {
@Value
(
"${paypal.mode}"
)
@Value
(
"${paypal.mode}"
)
private
String
mode
;
private
String
mode
;
@Bean
@Bean
public
Map
<
String
,
String
>
paypalSdkConfig
()
{
public
Map
<
String
,
String
>
paypalSdkConfig
()
{
Map
<
String
,
String
>
sdkConfig
=
new
HashMap
<>();
Map
<
String
,
String
>
sdkConfig
=
new
HashMap
<>();
...
@@ -30,16 +42,19 @@ public class PaypalConfig {
...
@@ -30,16 +42,19 @@ public class PaypalConfig {
return
sdkConfig
;
return
sdkConfig
;
}
}
@Scope
(
"prototype"
)
@Bean
@Bean
public
OAuthTokenCredential
authTokenCredential
()
{
public
OAuthTokenCredential
authTokenCredential
()
{
return
new
OAuthTokenCredential
(
clientId
,
clientSecret
,
paypalSdkConfig
());
return
new
OAuthTokenCredential
(
clientId
,
clientSecret
,
paypalSdkConfig
());
}
}
@
Primary
@
Scope
(
"prototype"
)
@Bean
@Bean
public
APIContext
apiContext
()
throws
PayPalREST
Exception
{
public
APIContext
apiContext
()
throws
IO
Exception
{
APIContext
apiContext
=
new
APIContext
(
authTokenCredential
().
getAccess
Token
());
APIContext
apiContext
=
new
APIContext
(
PayPalUtil
.
get
Token
());
apiContext
.
setConfigurationMap
(
paypalSdkConfig
());
apiContext
.
setConfigurationMap
(
paypalSdkConfig
());
return
apiContext
;
return
apiContext
;
}
}
}
}
\ No newline at end of file
src/main/java/com/example/afrishop_v3/util/PayPalUtil.java
0 → 100644
浏览文件 @
1632dfd2
package
com
.
example
.
afrishop_v3
.
util
;
import
com.squareup.okhttp.*
;
import
net.sf.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.io.IOException
;
public
class
PayPalUtil
{
//正式
// private static String url="https://api.paypal.com/v1";
//测试
private
static
String
url
=
"https://api.sandbox.paypal.com/v1"
;
public
static
String
getToken
()
throws
IOException
{
OkHttpClient
client
=
new
OkHttpClient
();
MediaType
mediaType
=
MediaType
.
parse
(
"application/x-www-form-urlencoded"
);
RequestBody
body
=
RequestBody
.
create
(
mediaType
,
"grant_type=client_credentials"
);
Request
request
=
new
Request
.
Builder
()
.
url
(
url
+
"/oauth2/token"
)
.
post
(
body
)
.
addHeader
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
.
addHeader
(
"Authorization"
,
"Bearer A21AAI3JoFShZn_xG0Pr6fjqDFQG2dWcDC2WePIM6qpFgplWmj-b9KfXm-crSa4cq6Z5PwmiE5DdMcNDzJoSsYrYCZd9myh2g"
)
.
addHeader
(
"cache-control"
,
"no-cache"
)
.
build
();
Response
response
=
client
.
newCall
(
request
).
execute
();
String
string
=
response
.
body
().
string
();
net
.
sf
.
json
.
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
string
);
String
token_type
=
jsonObject
.
getString
(
"token_type"
);
String
access_token
=
jsonObject
.
getString
(
"access_token"
);
String
token
=
String
.
format
(
"%s %s"
,
token_type
,
access_token
);
return
token
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论