Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
f062e533
提交
f062e533
authored
2月 27, 2021
作者:
吴德鹏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完整提交
上级
f14b0564
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
221 行增加
和
221 行删除
+221
-221
FlutterWaveController.java
...xample/afrishop_v3/controllers/FlutterWaveController.java
+2
-2
AfrishopV3ApplicationTests.java
...a/com/example/afrishop_v3/AfrishopV3ApplicationTests.java
+219
-219
没有找到文件。
src/main/java/com/example/afrishop_v3/controllers/FlutterWaveController.java
浏览文件 @
f062e533
...
...
@@ -81,7 +81,7 @@ public class FlutterWaveController extends Controller {
public
ResponseEntity
<
String
>
payForOrderByCard
(
@RequestParam
(
"orderId"
)
String
orderId
,
@RequestBody
FlutterWaveCard
flutterWaveCard
)
{
RaveConstant
.
PUBLIC_KEY
=
PUBLIC_KEY
;
RaveConstant
.
SECRET_KEY
=
SECRET_KEY
;
RaveConstant
.
ENVIRONMENT
=
Environment
.
STAGING
;
//or STAGING
RaveConstant
.
ENVIRONMENT
=
Environment
.
LIVE
;
//or LIVE
// Result result = new Result();
Optional
<
TbCfOrder
>
byId
=
repository
.
findById
(
orderId
);
...
...
@@ -135,7 +135,7 @@ public class FlutterWaveController extends Controller {
public
ResponseEntity
<
String
>
payForOrderByPhone
(
@RequestParam
(
"orderId"
)
String
orderId
,
@RequestBody
FlutterWaveCard
flutterWaveCard
)
{
RaveConstant
.
PUBLIC_KEY
=
PUBLIC_KEY
;
RaveConstant
.
SECRET_KEY
=
SECRET_KEY
;
RaveConstant
.
ENVIRONMENT
=
Environment
.
STAGING
;
//or STAGING
RaveConstant
.
ENVIRONMENT
=
Environment
.
LIVE
;
//or LIVE
// Result result = new Result();
Optional
<
TbCfOrder
>
byId
=
repository
.
findById
(
orderId
);
...
...
src/test/java/com/example/afrishop_v3/AfrishopV3ApplicationTests.java
浏览文件 @
f062e533
package
com
.
example
.
afrishop_v3
;
import
com.example.afrishop_v3.models.*
;
import
com.example.afrishop_v3.repository.CountryRepository
;
import
com.example.afrishop_v3.repository.TbCfOrderRepository
;
import
com.example.afrishop_v3.repository.TbCfStationItemRepository
;
import
com.example.afrishop_v3.repository.TokenRepository
;
import
com.example.afrishop_v3.util.IdUtil
;
import
com.example.afrishop_v3.util.OssUtil
;
import
com.example.afrishop_v3.util.PicUtils
;
import
com.google.gson.JsonObject
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.junit.Test
;
import
org.junit.runner.Result
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.web.client.RestTemplate
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.locks.ReentrantLock
;
import
java.util.stream.Collectors
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
AfrishopV3ApplicationTests
{
RestTemplate
restTemplate
=
new
RestTemplate
();
@Test
public
void
contextLoads
()
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
);
String
now
=
format
.
format
(
new
Date
());
System
.
out
.
println
(
now
);
}
private
String
url
=
"http://localhost:8099/afrishop/discover/bonus/saveNetworkMarketing"
;
@Autowired
private
TbCfOrderRepository
orderRepository
;
// post35789572fbf643cdab55901d1dc511a6
// userInfo00297bf300ed45e092a5182dececad21
// productSharervv32GmG4q
// amount0.9
// orderId008272b1fb994aef9b199449f46d5aa5
@Test
public
void
test1
()
{
Optional
<
TbCfOrder
>
byId
=
orderRepository
.
findById
(
"12a9d7d1042348278c97980a00fc67c4"
);
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"userInfo"
,
"32dcda5a709c4265a6f01686ae9b1c1c"
);
json
.
put
(
"amount"
,
byId
.
get
().
getItemsPrice
());
json
.
put
(
"orderId"
,
"12a9d7d1042348278c97980a00fc67c4"
);
System
.
out
.
println
(
json
);
ResponseEntity
<
Result
>
resultResponseEntity
=
restTemplate
.
postForEntity
(
url
,
json
,
Result
.
class
);
System
.
err
.
println
(
resultResponseEntity
);
}
@Autowired
private
TokenRepository
tokenRepository
;
@Autowired
private
CountryRepository
countryRepository
;
@Test
public
void
test2
()
{
List
list
=
new
ArrayList
();
list
.
add
(
2
);
list
.
add
(
1
);
list
.
add
(
3
);
list
.
forEach
(
System
.
out
::
println
);
}
private
ReentrantLock
reentrantLock
=
new
ReentrantLock
();
@Test
public
void
testImport
()
{
ExecutorService
executorService
=
Executors
.
newCachedThreadPool
();
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
executorService
.
execute
(()
->
importCountry
());
}
}
@Test
public
void
importCountry
()
{
String
url
=
"https://api.jisuapi.com/country/query?name=&continent=非洲&language=&iscountry=&appkey=732afb9ddae9eef8"
;
ResponseEntity
<
String
>
forEntity
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
String
body
=
forEntity
.
getBody
();
System
.
err
.
println
(
body
);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
body
);
String
status
=
jsonObject
.
getString
(
"status"
);
if
(
"0"
.
equals
(
status
))
{
JSONArray
jsonArray
=
jsonObject
.
getJSONArray
(
"result"
);
for
(
int
i
=
0
;
i
<
jsonArray
.
size
();
i
++)
{
Country
country
=
new
Country
();
JSONObject
object
=
jsonArray
.
getJSONObject
(
i
);
String
ename
=
object
.
getString
(
"ename"
);
String
cname
=
object
.
getString
(
"cname"
);
String
areaCode
=
object
.
getString
(
"areacode"
);
String
nationalFlag
=
object
.
getString
(
"nationalflag"
);
country
.
setAreaCode
(
areaCode
);
country
.
setCountryCname
(
cname
);
country
.
setCountryName
(
ename
);
country
.
setNationalFlag
(
nationalFlag
);
country
.
setId
(
IdUtil
.
createIdbyUUID
());
countryRepository
.
save
(
country
);
}
}
}
private
volatile
int
count
=
1
;
@Autowired
private
TbCfStationItemRepository
tbCfStationItemRepository
;
@Test
public
void
testImg
()
{
List
<
TbCfStationItem
>
list
=
tbCfStationItemRepository
.
queryItemsAll
();
try
{
for
(
TbCfStationItem
item
:
list
)
{
System
.
out
.
println
(
"压缩数量:"
+
count
++);
System
.
err
.
println
(
"商品ID:"
+
item
.
getItemId
());
String
itemImg
=
item
.
getItemImg
();
String
[]
urlArr
=
itemImg
.
split
(
";"
);
List
<
String
>
strList
=
new
ArrayList
<>();
for
(
String
url
:
urlArr
)
{
InputStream
stream
=
getImageStream
(
url
);
if
(
stream
==
null
)
{
continue
;
}
byte
[]
bytes
=
new
byte
[
0
];
try
{
bytes
=
toByteArray
(
stream
);
byte
[]
by
=
PicUtils
.
compressPicForScale
(
bytes
,
70
);
long
l
=
System
.
currentTimeMillis
();
String
urlName
=
UUID
.
randomUUID
()
+
"-"
+
String
.
valueOf
(
l
).
substring
(
6
)
+
".jpg"
;
String
compressedUrl
=
OssUtil
.
upload
(
by
,
urlName
,
"afrishop_new"
);
strList
.
add
(
compressedUrl
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
tbCfStationItemRepository
.
updateItmeImg
(
strList
.
stream
().
collect
(
Collectors
.
joining
(
";"
)),
item
.
getItemId
());
}
}
catch
(
Exception
e
)
{
}
finally
{
}
}
/**
* 通过URL获取网络图片
* 获取网络图片流
*
* @param url 传入的 URL 必须是以 http:// 开头的,因为我们使用了 HttpURLConnection
* @return 输入流
*/
public
static
InputStream
getImageStream
(
String
url
)
{
try
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
connection
.
setReadTimeout
(
10000
);
connection
.
setConnectTimeout
(
10000
);
connection
.
setRequestMethod
(
"GET"
);
if
(
connection
.
getResponseCode
()
==
HttpURLConnection
.
HTTP_OK
)
{
return
connection
.
getInputStream
();
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"获取网络图片出现异常,图片路径为:"
+
url
);
e
.
printStackTrace
();
}
return
null
;
}
/**
* 将 InputStream 流转换为 byte[]
*
* @param input InputStream
* @return byte[]
* @throws IOException IO流异常
*/
public
static
byte
[]
toByteArray
(
InputStream
input
)
throws
IOException
{
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
*
4
];
int
n
=
0
;
while
(-
1
!=
(
n
=
input
.
read
(
buffer
)))
{
output
.
write
(
buffer
,
0
,
n
);
}
return
output
.
toByteArray
();
}
}
//
package com.example.afrishop_v3;
//
//
import com.example.afrishop_v3.models.*;
//
import com.example.afrishop_v3.repository.CountryRepository;
//
import com.example.afrishop_v3.repository.TbCfOrderRepository;
//
import com.example.afrishop_v3.repository.TbCfStationItemRepository;
//
import com.example.afrishop_v3.repository.TokenRepository;
//
import com.example.afrishop_v3.util.IdUtil;
//
import com.example.afrishop_v3.util.OssUtil;
//
import com.example.afrishop_v3.util.PicUtils;
//
import com.google.gson.JsonObject;
//
import net.sf.json.JSONArray;
//
import net.sf.json.JSONObject;
//
import org.junit.Test;
//
import org.junit.runner.Result;
//
import org.junit.runner.RunWith;
//
import org.springframework.beans.factory.annotation.Autowired;
//
import org.springframework.boot.test.context.SpringBootTest;
//
import org.springframework.http.ResponseEntity;
//
import org.springframework.test.context.junit4.SpringRunner;
//
import org.springframework.web.client.RestTemplate;
//
//
import java.io.ByteArrayOutputStream;
//
import java.io.IOException;
//
import java.io.InputStream;
//
import java.net.HttpURLConnection;
//
import java.net.URL;
//
import java.text.SimpleDateFormat;
//
import java.time.LocalDateTime;
//
import java.util.*;
//
import java.util.concurrent.ExecutorService;
//
import java.util.concurrent.Executors;
//
import java.util.concurrent.Future;
//
import java.util.concurrent.locks.ReentrantLock;
//
import java.util.stream.Collectors;
//
//
@RunWith(SpringRunner.class)
//
@SpringBootTest
//
public class AfrishopV3ApplicationTests {
//
//
RestTemplate restTemplate = new RestTemplate();
//
//
@Test
//
public void contextLoads() {
//
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//
String now = format.format(new Date());
//
System.out.println(now);
//
}
//
//
private String url = "http://localhost:8099/afrishop/discover/bonus/saveNetworkMarketing";
//
@Autowired
//
private TbCfOrderRepository orderRepository;
//
//
//
post35789572fbf643cdab55901d1dc511a6
//
//
userInfo00297bf300ed45e092a5182dececad21
//
//
productSharervv32GmG4q
//
//
amount0.9
//
//
orderId008272b1fb994aef9b199449f46d5aa5
//
//
@Test
//
public void test1() {
//
//
Optional<TbCfOrder> byId = orderRepository.findById("12a9d7d1042348278c97980a00fc67c4");
//
JSONObject json = new JSONObject();
//
json.put("userInfo", "32dcda5a709c4265a6f01686ae9b1c1c");
//
json.put("amount", byId.get().getItemsPrice());
//
json.put("orderId", "12a9d7d1042348278c97980a00fc67c4");
//
System.out.println(json);
//
ResponseEntity<Result> resultResponseEntity = restTemplate.postForEntity(url, json, Result.class);
//
System.err.println(resultResponseEntity);
//
}
//
//
@Autowired
//
private TokenRepository tokenRepository;
//
//
@Autowired
//
private CountryRepository countryRepository;
//
//
//
@Test
//
public void test2() {
//
List list = new ArrayList();
//
list.add(2);
//
list.add(1);
//
list.add(3);
//
list.forEach(System.out::println);
//
//
}
//
//
private ReentrantLock reentrantLock = new ReentrantLock();
//
//
@Test
//
public void testImport() {
//
ExecutorService executorService = Executors.newCachedThreadPool();
//
//
for (int i = 0; i < 20; i++) {
//
executorService.execute(() -> importCountry());
//
}
//
//
}
//
//
@Test
//
public void importCountry() {
//
//
String url = "https://api.jisuapi.com/country/query?name=&continent=非洲&language=&iscountry=&appkey=732afb9ddae9eef8";
//
ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
//
String body = forEntity.getBody();
//
System.err.println(body);
//
JSONObject jsonObject = JSONObject.fromObject(body);
//
String status = jsonObject.getString("status");
//
if ("0".equals(status)) {
//
JSONArray jsonArray = jsonObject.getJSONArray("result");
//
for (int i = 0; i < jsonArray.size(); i++) {
//
Country country = new Country();
//
JSONObject object = jsonArray.getJSONObject(i);
//
String ename = object.getString("ename");
//
String cname = object.getString("cname");
//
String areaCode = object.getString("areacode");
//
String nationalFlag = object.getString("nationalflag");
//
country.setAreaCode(areaCode);
//
country.setCountryCname(cname);
//
country.setCountryName(ename);
//
country.setNationalFlag(nationalFlag);
//
country.setId(IdUtil.createIdbyUUID());
//
countryRepository.save(country);
//
//
}
//
}
//
//
//
}
//
//
private volatile int count = 1;
//
@Autowired
//
private TbCfStationItemRepository tbCfStationItemRepository;
//
//
@Test
//
public void testImg() {
//
List<TbCfStationItem> list = tbCfStationItemRepository.queryItemsAll();
//
try {
//
//
for (TbCfStationItem item : list) {
//
System.out.println("压缩数量:" + count++);
//
System.err.println("商品ID:" + item.getItemId());
//
//
String itemImg = item.getItemImg();
//
String[] urlArr = itemImg.split(";");
//
List<String> strList = new ArrayList<>();
//
for (String url : urlArr) {
//
//
InputStream stream = getImageStream(url);
//
if (stream == null) {
//
continue;
//
}
//
byte[] bytes = new byte[0];
//
try {
//
bytes = toByteArray(stream);
//
byte[] by = PicUtils.compressPicForScale(bytes, 70);
//
long l = System.currentTimeMillis();
//
String urlName = UUID.randomUUID() + "-" + String.valueOf(l).substring(6) + ".jpg";
//
//
String compressedUrl = OssUtil.upload(by, urlName, "afrishop_new");
//
strList.add(compressedUrl);
//
} catch (Exception e) {
//
e.printStackTrace();
//
}
//
}
//
tbCfStationItemRepository.updateItmeImg(strList.stream().collect(Collectors.joining(";")), item.getItemId());
//
}
//
//
} catch (Exception e) {
//
//
} finally {
//
//
//
}
//
}
//
//
/**
//
* 通过URL获取网络图片
//
* 获取网络图片流
//
*
//
* @param url 传入的 URL 必须是以 http:// 开头的,因为我们使用了 HttpURLConnection
//
* @return 输入流
//
*/
//
public static InputStream getImageStream(String url) {
//
try {
//
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
//
connection.setReadTimeout(10000);
//
connection.setConnectTimeout(10000);
//
connection.setRequestMethod("GET");
//
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
//
return connection.getInputStream();
//
}
//
} catch (IOException e) {
//
System.out.println("获取网络图片出现异常,图片路径为:" + url);
//
e.printStackTrace();
//
}
//
return null;
//
}
//
//
/**
//
* 将 InputStream 流转换为 byte[]
//
*
//
* @param input InputStream
//
* @return byte[]
//
* @throws IOException IO流异常
//
*/
//
public static byte[] toByteArray(InputStream input) throws IOException {
//
ByteArrayOutputStream output = new ByteArrayOutputStream();
//
byte[] buffer = new byte[1024 * 4];
//
int n = 0;
//
while (-1 != (n = input.read(buffer))) {
//
output.write(buffer, 0, n);
//
}
//
return output.toByteArray();
//
}
//
//
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论