commit | author | age
|
9bcb19
|
1 |
/* |
I |
2 |
Copyright [2020] [https://www.xiaonuo.vip] |
|
3 |
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
you may not use this file except in compliance with the License. |
|
6 |
You may obtain a copy of the License at |
|
7 |
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
|
|
10 |
Unless required by applicable law or agreed to in writing, software |
|
11 |
distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
See the License for the specific language governing permissions and |
|
14 |
limitations under the License. |
|
15 |
|
|
16 |
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: |
|
17 |
|
|
18 |
1.请不要删除和修改根目录下的LICENSE文件。 |
|
19 |
2.请不要删除和修改Snowy源码头部的版权声明。 |
|
20 |
3.请保留源码和相关描述文件的项目出处,作者声明等。 |
|
21 |
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
22 |
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
23 |
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip |
|
24 |
*/ |
|
25 |
package vip.xiaonuo.core.sms.modular.aliyun.msign.impl; |
|
26 |
|
|
27 |
import cn.hutool.log.Log; |
|
28 |
import vip.xiaonuo.core.sms.modular.aliyun.msign.MultiSignManager; |
|
29 |
|
|
30 |
import java.util.Map; |
|
31 |
import java.util.concurrent.ConcurrentHashMap; |
|
32 |
|
|
33 |
/** |
|
34 |
* 获取缓存的map中的签名 |
|
35 |
* |
|
36 |
* @author xuyuxiang |
|
37 |
* @date 2018-09-21-上午10:49 |
|
38 |
*/ |
|
39 |
public class MapBasedMultiSignManager implements MultiSignManager { |
|
40 |
|
|
41 |
private static final Log log = Log.get(); |
|
42 |
|
|
43 |
private static final int CLEAR_COUNT = 1000; |
|
44 |
|
|
45 |
private final Map<String, String> cacheMap = new ConcurrentHashMap<>(); |
|
46 |
|
|
47 |
@Override |
|
48 |
public String getSign(String phone, String signName) { |
|
49 |
|
|
50 |
//先清除map |
|
51 |
clearMap(); |
|
52 |
|
|
53 |
//分割签名数组 |
|
54 |
String[] signNames = signName.split(","); |
|
55 |
|
|
56 |
//获取上次发送的时候用的哪个签名,这次换一个 |
|
57 |
Object lastSignName = cacheMap.get(phone); |
|
58 |
if (lastSignName == null) { |
|
59 |
cacheMap.put(phone, signNames[0]); |
|
60 |
log.info(">>> 发送短信,签名为:" + signNames[0] + ",电话为:" + phone); |
|
61 |
return signNames[0]; |
|
62 |
} else { |
|
63 |
for (String name : signNames) { |
|
64 |
if (!name.equals(lastSignName)) { |
|
65 |
cacheMap.put(phone, name); |
|
66 |
log.info(">>> 发送短信,签名为:" + name + ",电话为:" + phone); |
|
67 |
return name; |
|
68 |
} |
|
69 |
} |
|
70 |
cacheMap.put(phone, signNames[0]); |
|
71 |
log.info(">>> 发送短信,签名为:" + signNames[0] + ",电话为:" + phone); |
|
72 |
return signNames[0]; |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* 每隔一段时间清除下map |
|
78 |
* |
|
79 |
* @author xuyuxiang |
|
80 |
* @date 2018/9/21 上午10:57 |
|
81 |
*/ |
|
82 |
private void clearMap() { |
|
83 |
if (cacheMap.size() >= CLEAR_COUNT) { |
|
84 |
cacheMap.clear(); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
} |