package com.liangjian.dataplatform.member.controller;

import com.jfinal.weixin.sdk.api.ApiResult;
import com.liangjian.dataplatform.member.api.MySnsApi;
import com.liangjian.dataplatform.member.entity.response.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Author: 黄子奇
 * @Date: 2019/11/27
 */
@Controller
@RequestMapping("/weixin")
public class WeixinIndexController {
    @Autowired
    private WeixinController weixinController;

    @GetMapping("/entrance")
    public String entrance(@RequestParam(required = false) Boolean hasCode, @RequestParam String code) {
        if(hasCode == null || !hasCode) {
            ApiResult apiResult = MySnsApi.oauth2(code);
            String openid = apiResult.getStr("openid");
            return "redirect:https://mem.360lj.com/weixin/entrance?hasCode=true&code="+openid;
        }
        return "index";
    }
}
