Commit 2d7a5532266d94a38e3117f326514d4612ab60bd
1 parent
0421d011
拆分 get 和 post 签名的 java代码示例。
Showing
1 changed file
with
22 additions
and
10 deletions
0. 公共组件/1.1 SHA1签名.md
| ... | ... | @@ -16,21 +16,33 @@ SHA1 加密 |
| 16 | 16 | |
| 17 | 17 | #### 代码示例 |
| 18 | 18 | |
| 19 | -```java | |
| 19 | +```java | |
| 20 | 20 | |
| 21 | + //生成get 方式 带签名的请求URL | |
| 21 | 22 | public static void main(String[] args) { |
| 22 | - String sp_key = "672db30805f848f59ec3728f8347a4a0"; //找相关开发者获取 | |
| 23 | + String sp_key = "xxxxxxxxxxx"; //开发者帐号对应的key. 请开发者谨慎保管此值。 | |
| 23 | 24 | Map<String, String> map = new HashMap<String,String>(); |
| 24 | - map.put("sp_id","iqhpk8pl19"); //找相关开发者获取 | |
| 25 | - map.put("mobile", "13520335460"); | |
| 26 | - map.put("content", "你好,test"); | |
| 27 | 25 | |
| 28 | - //生成get 方式 请求 | |
| 29 | - String getUrl = buildURL("http://localhost:9091/openapi/api/CnliveMobile/sendMsg",map, sp_key); | |
| 30 | - System.out.println(getUrl); | |
| 31 | - //生成 post 方式签名 | |
| 32 | - //String sign = sign(map, sp_key); | |
| 26 | + map.put("sp_id","iqhpk8pl19"); //开发者帐号对应的10位ID ,所有接口参数都必须有此参数。 | |
| 27 | + map.put("param1_keyname", "Parm1_vaule"); //接口需要的参数1 | |
| 28 | + map.put("param2_keyname", "Parm2_vaule"); //接口需要的参数2 。。。 等等 | |
| 29 | + | |
| 30 | + String getUrl = buildURL("http://api.cnlive.com/open/api/xxxxxxx",map, sp_key); | |
| 31 | + System.out.println(getUrl); | |
| 33 | 32 | } |
| 33 | + | |
| 34 | + //生成post方式的请求参数签名 | |
| 35 | + public static void main(String[] args) { | |
| 36 | + String sp_key = "xxxxxxxxxxx"; //开发者帐号对应的key. 请开发者谨慎保管此值。 | |
| 37 | + Map<String, String> map = new HashMap<String,String>(); | |
| 38 | + | |
| 39 | + map.put("sp_id","iqhpk8pl19"); //开发者帐号对应的10位ID ,所有接口参数都必须有此参数。 | |
| 40 | + map.put("param1_keyname", "Parm1_vaule"); //接口需要的参数1 | |
| 41 | + map.put("param2_keyname", "Parm2_vaule"); //接口需要的参数2 。。。 等等 | |
| 42 | + | |
| 43 | + String post_param_signed = sign(map, sp_key); | |
| 44 | + System.out.println(post_param_signed); | |
| 45 | + } | |
| 34 | 46 | |
| 35 | 47 | /** |
| 36 | 48 | * 生成URL | ... | ... |