Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
483f0976
提交
483f0976
authored
12月 05, 2019
作者:
zgy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
短信发送方法封装
上级
d839b542
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
254 行增加
和
120 行删除
+254
-120
pom.xml
pom.xml
+10
-5
FlutterWaveServiceImpl.java
.../zion/chinafrica/service/impl/FlutterWaveServiceImpl.java
+3
-3
MessageUtil.java
src/main/java/com/diaoyun/zion/master/util/MessageUtil.java
+9
-0
SMSUtil.java
src/main/java/com/diaoyun/zion/master/util/SMSUtil.java
+151
-105
application.yml
src/main/resources/application.yml
+5
-5
PayTest.java
src/test/java/com/diaoyun/zion/PayTest.java
+76
-2
没有找到文件。
pom.xml
浏览文件 @
483f0976
...
...
@@ -25,6 +25,11 @@
<dependencies>
<dependency>
<groupId>
com.yunpian.sdk
</groupId>
<artifactId>
yunpian-java-sdk
</artifactId>
<version>
1.2.7
</version>
</dependency>
<dependency>
<groupId>
io.netty
</groupId>
<artifactId>
netty-all
</artifactId>
...
...
@@ -190,11 +195,11 @@
</dependency>
<!--net.sf.json-lib-->
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency
>
<groupId>
org.apache.httpcomponents
</groupId
>
<artifactId>
httpclient
</artifactId
>
<!--<version>4.5.2</version>
-->
</dependency
>
<!-- <dependency>--
>
<!-- <groupId>org.apache.httpcomponents</groupId>--
>
<!-- <artifactId>httpclient</artifactId>--
>
<!-- <!–<version>4.5.2</version>–>
-->
<!-- </dependency>--
>
<!--apache httpclient-->
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/impl/FlutterWaveServiceImpl.java
浏览文件 @
483f0976
...
...
@@ -65,9 +65,9 @@ public class FlutterWaveServiceImpl implements FlutterWaveService {
private
String
FLUTTERWAVE_REFUND_URL
=
"https://api.ravepay.co/gpx/merchant/transactions/refund"
;
//校验API
private
String
VERIFY_PAY_URL
=
"https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify"
;
private
String
VERIFY_PAY_URL
=
"https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify"
;
//测试API
//
private String VERIFY_PAY_URL = "https://ravesandboxapi.flutterwave.com/flwv3-pug/getpaidx/api/v2/verify";
//
private String VERIFY_PAY_URL = "https://ravesandboxapi.flutterwave.com/flwv3-pug/getpaidx/api/v2/verify";
/**
* 使用卡号支付(预支付)
...
...
@@ -80,7 +80,7 @@ public class FlutterWaveServiceImpl implements FlutterWaveService {
public
Result
payForOrder
(
String
orderId
,
FlutterWaveCard
flutterWaveCard
)
{
RaveConstant
.
PUBLIC_KEY
=
domainProperties
.
getProperty
(
"flutterwave.public.key"
);
RaveConstant
.
SECRET_KEY
=
domainProperties
.
getProperty
(
"flutterwave.secret.key"
);
RaveConstant
.
ENVIRONMENT
=
Environment
.
STAGING
;
//or live
RaveConstant
.
ENVIRONMENT
=
Environment
.
LIVE
;
//or live
Result
result
=
new
Result
();
TbCfOrderVo
tbCfOrderVo
=
(
TbCfOrderVo
)
orderRedisCache
.
get
(
KeyConstant
.
ORDER_DET
+
orderId
);
TbCfOrderEntity
orderEntity
=
tbCfOrderDao
.
queryObject
(
orderId
);
...
...
src/main/java/com/diaoyun/zion/master/util/MessageUtil.java
0 → 100644
浏览文件 @
483f0976
package
com
.
diaoyun
.
zion
.
master
.
util
;
/**
* @Auther: wudepeng
* @Date: 2019/12/04
* @Description:
*/
public
class
MessageUtil
{
}
src/main/java/com/diaoyun/zion/master/util/SMSUtil.java
浏览文件 @
483f0976
...
...
@@ -9,6 +9,9 @@ import java.util.List;
import
java.util.Map
;
import
com.yunpian.sdk.YunpianClient
;
import
com.yunpian.sdk.constant.YunpianConstant
;
import
com.yunpian.sdk.model.SmsBatchSend
;
import
org.apache.commons.lang3.RandomStringUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.NameValuePair
;
...
...
@@ -19,110 +22,113 @@ import org.apache.http.impl.client.CloseableHttpClient;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
import
org.junit.Test
;
/**
* 短信接口类
* @author lyl
*
* @author lyl
* <p>
* 2018年4月18日
*/
public
class
SMSUtil
{
//查账户信息的http地址
private
static
String
URI_GET_USER_INFO
=
"https://sms.yunpian.com/v2/user/get.json"
;
//查账户信息的http地址
private
static
String
URI_GET_USER_INFO
=
"https://sms.yunpian.com/v2/user/get.json"
;
//模板发送接口的http地址
//模板发送接口的http地址
private
static
String
URI_TPL_SEND_SMS
=
"https://sms.yunpian.com/v2/sms/tpl_single_send.json"
;
//private static String URI_TPL_SEND_SMS =
"https://sms.yunpian.com/v2/sms/single_send.json";
//编码格式。发送编码格式统一用UTF-8
private
static
String
URI_SINGLE_SEND_SMS
=
"https://sms.yunpian.com/v2/sms/single_send.json"
;
//编码格式。发送编码格式统一用UTF-8
private
static
String
ENCODING
=
"UTF-8"
;
private
String
API_KEY
=
"cb20310db0e7dcc76a827afbd2ba548f"
;
private
static
String
API_KEY
=
"cb20310db0e7dcc76a827afbd2ba548f"
;
/**
* 查询用户信息
*
* @param apikey
* @return
* @throws IOException
* @throws URISyntaxException
*/
public
static
String
getUserInfo
(
String
apikey
)
throws
IOException
,
URISyntaxException
{
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
params
.
put
(
"apikey"
,
apikey
);
return
post
(
URI_GET_USER_INFO
,
params
);
}
/**
* 提交响应
*
* @param url
* @param paramsMap
* @return
*/
public
static
String
post
(
String
url
,
Map
<
String
,
String
>
paramsMap
)
{
CloseableHttpClient
client
=
HttpClients
.
createDefault
();
String
responseText
=
""
;
CloseableHttpResponse
response
=
null
;
try
{
HttpPost
method
=
new
HttpPost
(
url
);
if
(
paramsMap
!=
null
)
{
List
<
NameValuePair
>
paramList
=
new
ArrayList
<
NameValuePair
>();
for
(
Map
.
Entry
<
String
,
String
>
param
:
paramsMap
.
entrySet
())
{
NameValuePair
pair
=
new
BasicNameValuePair
(
param
.
getKey
(),
param
.
getValue
());
paramList
.
add
(
pair
);
}
method
.
setEntity
(
new
UrlEncodedFormEntity
(
paramList
,
ENCODING
));
}
response
=
client
.
execute
(
method
);
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
responseText
=
EntityUtils
.
toString
(
entity
,
ENCODING
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
response
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
responseText
;
}
/**
* 查询用户信息
*
* @param apikey
* @return
* @throws IOException
* @throws URISyntaxException
*/
public
static
String
getUserInfo
(
String
apikey
)
throws
IOException
,
URISyntaxException
{
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
params
.
put
(
"apikey"
,
apikey
);
return
post
(
URI_GET_USER_INFO
,
params
);
}
/**
* 提交响应
*
* @param url
* @param paramsMap
* @return
*/
public
static
String
post
(
String
url
,
Map
<
String
,
String
>
paramsMap
)
{
CloseableHttpClient
client
=
HttpClients
.
createDefault
();
String
responseText
=
""
;
CloseableHttpResponse
response
=
null
;
try
{
HttpPost
method
=
new
HttpPost
(
url
);
if
(
paramsMap
!=
null
)
{
List
<
NameValuePair
>
paramList
=
new
ArrayList
<
NameValuePair
>();
for
(
Map
.
Entry
<
String
,
String
>
param
:
paramsMap
.
entrySet
())
{
NameValuePair
pair
=
new
BasicNameValuePair
(
param
.
getKey
(),
param
.
getValue
());
paramList
.
add
(
pair
);
}
method
.
setEntity
(
new
UrlEncodedFormEntity
(
paramList
,
ENCODING
));
}
response
=
client
.
execute
(
method
);
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
responseText
=
EntityUtils
.
toString
(
entity
,
ENCODING
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
response
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
responseText
;
}
/**
* 发送验证码
*
* @return
* @throws IOException
*/
public
String
yzCode
(
String
phone
)
throws
IOException
{
if
(
phone
.
equals
(
null
)){
return
"error"
;
}
//编码格式。发送编码格式统一用UTF-8
String
ENCODING
=
"UTF-8"
;
long
tpl_id
=
3253208
;
//模板ID
String
code
=
RandomStringUtils
.
randomNumeric
(
6
);
// 生成6位随机验证码
String
tpl_value
=
URLEncoder
.
encode
(
"#code#"
,
ENCODING
)
+
"="
+
URLEncoder
.
encode
(
code
,
ENCODING
)
;
System
.
out
.
println
(
tpl_value
);
* 发送验证码
*
* @return
* @throws IOException
*/
public
static
String
yzCode
(
String
phone
)
throws
IOException
{
if
(
phone
.
equals
(
null
))
{
return
"error"
;
}
//编码格式。发送编码格式统一用UTF-8
String
ENCODING
=
"UTF-8"
;
long
tpl_id
=
3253208
;
//模板ID
String
code
=
RandomStringUtils
.
randomNumeric
(
6
);
// 生成6位随机验证码
String
tpl_value
=
URLEncoder
.
encode
(
"#code#"
,
ENCODING
)
+
"="
+
URLEncoder
.
encode
(
code
,
ENCODING
);
System
.
out
.
println
(
tpl_value
);
System
.
out
.
println
(
SMSUtil
.
tplSendSms
(
API_KEY
,
tpl_id
,
tpl_value
,
phone
));
return
code
;
}
/**
* 通过模板发送短信
*
* @param apikey
* @param tpl_id
* @param tpl_value
* @param mobile
* @return
* @throws IOException
*/
public
static
String
tplSendSms
(
String
apikey
,
long
tpl_id
,
String
tpl_value
,
String
mobile
)
throws
IOException
{
return
code
;
}
/**
* 通过模板发送短信
*
* @param apikey
* @param tpl_id
* @param tpl_value
* @param mobile
* @return
* @throws IOException
*/
public
static
String
tplSendSms
(
String
apikey
,
long
tpl_id
,
String
tpl_value
,
String
mobile
)
throws
IOException
{
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
params
.
put
(
"apikey"
,
apikey
);
params
.
put
(
"tpl_id"
,
String
.
valueOf
(
tpl_id
));
...
...
@@ -130,18 +136,58 @@ public class SMSUtil {
params
.
put
(
"mobile"
,
mobile
);
return
post
(
URI_TPL_SEND_SMS
,
params
);
}
public
static
String
singleSend
(
String
apikey
,
String
text
,
String
mobile
)
{
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
//请求参数集合
params
.
put
(
"apikey"
,
apikey
);
params
.
put
(
"text"
,
text
);
params
.
put
(
"mobile"
,
mobile
);
return
post
(
"https://sms.yunpian.com/v2/sms/single_send.json"
,
params
);
//请自行使用post方式请求,可使用Apache HttpClient
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
// SMSUtil.singleSend(URI_TPL_SEND_SMS,"code","+8613751400455");
SMSUtil
s
=
new
SMSUtil
();
String
s1
=
s
.
yzCode
(
"+260972134374"
);
}
/**
* 通过模板群发(新版)
*
* @param phone
* @param tplId
* @param tplVal
*/
public
static
void
sendMessageByTpl
(
String
phone
,
String
tplId
,
String
tplVal
)
{
YunpianClient
clnt
=
new
YunpianClient
(
API_KEY
).
init
();
Map
<
String
,
String
>
param
=
clnt
.
newParam
(
5
);
param
.
put
(
YunpianConstant
.
MOBILE
,
phone
);
param
.
put
(
YunpianConstant
.
TPL_ID
,
tplId
);
String
code
=
RandomStringUtils
.
randomNumeric
(
6
);
param
.
put
(
YunpianConstant
.
TPL_VALUE
,
tplVal
);
com
.
yunpian
.
sdk
.
model
.
Result
<
SmsBatchSend
>
r
=
clnt
.
sms
().
tpl_batch_send
(
param
);
System
.
out
.
println
(
r
);
}
/**
* 群发短信(新版)
*
* @param phone
* @param text
*/
public
static
void
sendMessageByText
(
String
phone
,
String
text
)
{
YunpianClient
clnt
=
new
YunpianClient
(
API_KEY
).
init
();
Map
<
String
,
String
>
param
=
clnt
.
newParam
(
5
);
param
.
put
(
YunpianConstant
.
MOBILE
,
phone
);
String
code
=
RandomStringUtils
.
randomNumeric
(
6
);
param
.
put
(
YunpianConstant
.
TEXT
,
text
);
com
.
yunpian
.
sdk
.
model
.
Result
<
SmsBatchSend
>
result
=
clnt
.
sms
().
batch_send
(
param
);
System
.
out
.
println
(
result
);
}
/**
* 发送物流短信
*
* @param phone
*/
public
static
void
sendLogisticsMessage
(
String
phone
)
{
String
message
=
"【Afrishop】Thank you for shopping with Afrishop! Your parcel has arrived in Zambia."
;
sendMessageByText
(
phone
,
message
);
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
String
phone
=
"13751400455,18607444177"
;
SMSUtil
.
sendLogisticsMessage
(
phone
);
}
}
src/main/resources/application.yml
浏览文件 @
483f0976
...
...
@@ -39,12 +39,12 @@ spring:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.cj.jdbc.Driver
# 测试环境
url
:
jdbc:mysql://47.106.242.175:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
username
:
root
password
:
diaoyun666
# url: jdbc:mysql://159.138.48.71:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
# url: jdbc:mysql://47.106.242.175:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
# username: root
# password: Diaoyunnuli.8
# password: diaoyun666
url
:
jdbc:mysql://159.138.48.71:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
username
:
root
password
:
Diaoyunnuli.8
# 连接池配置
initial-size
:
5
...
...
src/test/java/com/diaoyun/zion/PayTest.java
浏览文件 @
483f0976
...
...
@@ -14,9 +14,17 @@ import com.mashape.unirest.http.Headers;
import
com.mashape.unirest.http.HttpResponse
;
import
com.mashape.unirest.http.Unirest
;
import
com.mashape.unirest.http.exceptions.UnirestException
;
import
com.yunpian.sdk.YunpianClient
;
import
com.yunpian.sdk.api.SmsApi
;
import
com.yunpian.sdk.api.TplApi
;
import
com.yunpian.sdk.api.YunpianApi
;
import
com.yunpian.sdk.constant.YunpianConstant
;
import
com.yunpian.sdk.model.SmsBatchSend
;
import
com.yunpian.sdk.model.SmsSingleSend
;
import
io.swagger.models.auth.In
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.apache.commons.lang3.RandomStringUtils
;
import
org.apache.http.Consts
;
import
org.apache.http.HttpRequest
;
import
org.junit.Test
;
...
...
@@ -29,6 +37,7 @@ import java.io.UnsupportedEncodingException;
import
java.net.MalformedURLException
;
import
java.net.URISyntaxException
;
import
java.net.URLDecoder
;
import
java.net.URLEncoder
;
import
java.util.*
;
import
static
com
.
github
.
pagehelper
.
page
.
PageMethod
.
startPage
;
...
...
@@ -123,7 +132,7 @@ public class PayTest {
@Test
public
void
testHeaders
()
throws
UnirestException
{
public
void
testHeaders
()
throws
UnirestException
{
// String url = "https://7f0e048ac4016b9357bb1eb2217e4201:1c97a1222c5b40e0597c816c6dfecac0@mollykitty.myshopify.com/admin/api/2019-10/products.json";
// Map<String, Object> map = new HashMap<>();
// map.put("product_type", "Men");
...
...
@@ -141,9 +150,74 @@ public class PayTest {
String
str
=
link
.
get
(
0
);
String
[]
split
=
str
.
split
(
","
);
String
s
=
split
[
0
];
System
.
out
.
println
(
s
.
substring
(
s
.
lastIndexOf
(
"page_info="
),
s
.
lastIndexOf
(
">;"
)));
System
.
out
.
println
(
s
.
substring
(
s
.
lastIndexOf
(
"page_info="
),
s
.
lastIndexOf
(
">;"
)));
}
/**
* 批量发送
*
* @throws UnsupportedEncodingException
*/
@Test
public
void
sendMessage
()
throws
UnsupportedEncodingException
{
// YunpianClient clnt = new YunpianClient("cb20310db0e7dcc76a827afbd2ba548f").init();
// Map<String, String> param = clnt.newParam(5);
// //param.put("tpl_id","3253208");
// param.put(YunpianConstant.MOBILE, "+260977598876");
String
code
=
RandomStringUtils
.
randomNumeric
(
6
);
// param.put(YunpianConstant.TEXT, "【Afrishop】you are logging in for verification, and the verification code is '" + code + "'.Do not disclose the verification code to others.");
// // param.put(EXTEND, "001");
// // param.put(UID, "10001");
// // param.put(CALLBACK_URL, "http://yourreceiveurl_address");
// com.yunpian.sdk.model.Result<SmsBatchSend> result = clnt.sms().batch_send(param);
// System.out.println(result);
String
text
=
"【Afrishop】you are logging in for verification, and the verification code is '"
+
code
+
"'.Do not disclose the verification code to others."
;
sendMessageByText
(
"13751400455"
,
text
);
}
public
void
sendMessageByText
(
String
phone
,
String
text
)
{
YunpianClient
clnt
=
new
YunpianClient
(
"cb20310db0e7dcc76a827afbd2ba548f"
).
init
();
Map
<
String
,
String
>
param
=
clnt
.
newParam
(
5
);
param
.
put
(
YunpianConstant
.
MOBILE
,
phone
);
String
code
=
RandomStringUtils
.
randomNumeric
(
6
);
param
.
put
(
YunpianConstant
.
TEXT
,
text
);
com
.
yunpian
.
sdk
.
model
.
Result
<
SmsBatchSend
>
result
=
clnt
.
sms
().
batch_send
(
param
);
System
.
out
.
println
(
result
);
}
@Test
public
void
sendTpl
()
{
// YunpianClient clnt = new YunpianClient("cb20310db0e7dcc76a827afbd2ba548f").init();
// Map<String, String> param = clnt.newParam(5);
// param.put(YunpianConstant.MOBILE, "13751400455");
// param.put(YunpianConstant.TPL_ID, "3253208");
// param.put(YunpianConstant.TPL_VALUE, "#code#=" + code);
String
code
=
RandomStringUtils
.
randomNumeric
(
6
);
sendMessageByTpl
(
"cb20310db0e7dcc76a827afbd2ba548f"
,
"13751400455"
,
"3253208"
,
"#code#="
+
code
);
}
/**
* 通过模板群发
*
* @param apiKey
* @param phone
* @param tplId
* @param tplVal
*/
public
void
sendMessageByTpl
(
String
apiKey
,
String
phone
,
String
tplId
,
String
tplVal
)
{
YunpianClient
clnt
=
new
YunpianClient
(
apiKey
).
init
();
Map
<
String
,
String
>
param
=
clnt
.
newParam
(
5
);
param
.
put
(
YunpianConstant
.
MOBILE
,
phone
);
param
.
put
(
YunpianConstant
.
TPL_ID
,
tplId
);
String
code
=
RandomStringUtils
.
randomNumeric
(
6
);
param
.
put
(
YunpianConstant
.
TPL_VALUE
,
tplVal
);
// param.put(EXTEND, "001");
// param.put(UID, "10001");
com
.
yunpian
.
sdk
.
model
.
Result
<
SmsBatchSend
>
r
=
clnt
.
sms
().
tpl_batch_send
(
param
);
System
.
out
.
println
(
r
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论