package cn.newfeifan.mall.module.mp.controller.login;

import cn.newfeifan.mall.framework.common.pojo.CommonResult;
import cn.newfeifan.mall.module.mp.controller.admin.account.vo.MpAccountCreateReqVO;
import cn.newfeifan.mall.module.mp.service.account.MpAccountService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.io.BufferedReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;

@Tag(name = "商城移动端 - 创建公众号账号")
@RestController
@RequestMapping("/mp/app")
@Validated
public class AppLoginController {

    @Resource
    private MpAccountService mpAccountService;

//    @PostMapping("/authorize")
//    @Operation(summary = "引导用户授权")
//    @PreAuthorize("@ss.hasPermission('mp:account:create')")
    public CommonResult<Long> createAccount(@Valid @RequestBody MpAccountCreateReqVO createReqVO) throws UnsupportedEncodingException {
        String appid = "wxbb000000000e";
        String uri = "wftest.zzff.net/wx/weixinLogin";
        uri = URLEncoder.encode(uri, "UTF-8");
        String result = "";
        BufferedReader in = null;

        try {
            String urlNameString = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + uri + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
        } catch (Exception e) {

        }
        return success(mpAccountService.createAccount(createReqVO));
    }


    // todo 创建一个接口, 用于接收回调信息


}
