admin
2019-12-28 64a8f7a3be0a5584fe2164a2474b189c79cfab5c
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
package com.yeshi.fanli.controller.wxmp;
 
import java.io.PrintWriter;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.wx.WXXCXUtil;
 
import com.yeshi.fanli.dto.WXMPAcceptData;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
 
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("/wxmp/api/v1/user")
public class UserController {
 
    @RequestMapping("getOpenId")
    public void getOpenId(WXMPAcceptData acceptData, String code, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(code)) {
            out.print(JsonUtil.loadFalseResult("code为空"));
            return;
        }
 
        String openId = WXXCXUtil.getOpenId(Constant.WXMP_APP_INFO, code);
        if (!StringUtil.isNullOrEmpty(openId)) {
            JSONObject data = new JSONObject();
            data.put("openId", openId);
            out.print(JsonUtil.loadTrueResult(data));
        } else {
            out.print(JsonUtil.loadFalseResult("openId获取失败"));
        }
    }
}