Blame view

doc/server_document.md 1.58 KB
d0017e7e1   李康   init document
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  1. 充值通知第三方服务端接口(需提供回调地址)
  -----------------------------
      参数列表:
          orderId:   订单id  
          appId:  游戏接入分配appid  
          userId: 平台用户id   
          product: 购买商品名字   
          extraInfo:游戏接入方传入自定义参数,200字符
          currency:币种 (目前仅有CNY)     
          amount:充值金额(分)        
          sig:  签名(算法详见2)
          
      第三方server端返回值:
          如果第三方验证成功,则返回字符串"success"即可,否则会通知10次后停止.
          
          
  2.签名算法
  --------------------------------
  
      注意:签名参数不能写成固定数量,一定要获取全部参数并且除sig参数外,然后按照字母升序排列。
  ```java
  
  	/**
  	 * 签名算法
  	 * @param request
  	 * @return
  	 */
  	public String sig(HttpServletRequest request, String key){
  		
  		Enumeration names = request.getParameterNames();
  		SortedSet<String> allParams = Sets.newTreeSet();
  		 
  		while (names.hasMoreElements()) {
  		    String name = (String) names.nextElement();
  		    if (name.equals("sig")) {
  		        continue;
  		    }
  		 
  		    try {
  				allParams.add(name + "=" + URLEncoder.encode(request.getParameter(name), "utf-8"));
  			} catch (UnsupportedEncodingException e) {
  				e.printStackTrace();
  			}
  		}
  		
  		String params = Joiner.on("&").join(allParams)+key;
  		String computedToken = DigestUtils.md5DigestAsHex(params.getBytes());
  		return computedToken;
  	}
  ```
  
  
  
      注意:参数是按字母升序排列  akey=value&bkey=value.... + secretkey