package com.patzn.lims.security.controller;//package ops.china.service.upms.security.controller;
//
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import com.baomidou.mybatisplus.extension.api.R;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import com.baomidou.kisso.annotation.Action;
//import com.baomidou.kisso.annotation.Login;
//import com.baomidou.mybatisplus.extension.api.Assert;
//
//import cn.binarywang.wx.miniapp.api.WxMaService;
//import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import me.chanjar.weixin.common.error.WxErrorException;
//import com.patzn.lims.sys.enums.WxTypeEnum;
//import com.patzn.lims.sys.service.ISysUserService;
//import ops.china.service.web.SuperController;
//
///**
// * <p>
// * 微信相关控制器
// * </p>
// * <p>
// * https://github.com/binarywang/weixin-java-miniapp-demo
// * https://developers.weixin.qq.com/miniprogram/dev/api/api-login.html
// * </p>
// *
// * @author hubin
// * @since 2018-04-26
// */
//@Api(tags = "微信相关")
//@RestController
//@RequestMapping("/v1/wechat")
//public class WechatController extends SuperController {
//
//    @Autowired
//    private WxMaService wxService;
//    @Autowired
//    private ISysUserService sysUserService;
//
//
//    @ApiOperation(value = "微信小程序登录", notes = "微信小程序 js_code 换取 token")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "小程序 CODE", required = true, paramType = "path", dataType = "String"),
//    })
//    @Login(action = Action.Skip)
//    @PostMapping("malogin_{code}")
//    public R<String> malogin(@PathVariable("code") String code) {
//        String token = null;
//        try {
//            // 微信小程序授权信息
//            WxMaJscode2SessionResult result = this.wxService.getUserService().getSessionInfo(code);
//            PtAssert.fail(StringUtils.isEmpty(result.getOpenid()), "js code error");
//            token = sysUserService.loginWxMa(request, result.getOpenid());
//        } catch (WxErrorException e) {
//            PtAssert.fail(e.getMessage());
//        }
//        return success(token);
//    }
//
//
//    @ApiOperation(value = "微信小程序绑定", notes = "微信小程序绑定平台已有账号")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "小程序 CODE", required = true, paramType = "path", dataType = "String"),
//            @ApiImplicitParam(name = "username", value = "用户名", required = true, paramType = "query", dataType = "String"),
//            @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query", dataType = "String"),
//    })
//    @Login(action = Action.Skip)
//    @PostMapping(value = "/mabind_{code}")
//    public R<String> mabind(@PathVariable("code") String code,
//                                     @RequestParam("username") String username,
//                                     @RequestParam("password") String password) {
//        String token = null;
//        try {
//            // 微信小程序授权信息
//            WxMaJscode2SessionResult result = this.wxService.getUserService().getSessionInfo(code);
//            PtAssert.fail(StringUtils.isEmpty(result.getOpenid()), "js code error");
//            token = sysUserService.loginToken(request, WxTypeEnum.MA, result.getOpenid(), username, password);
//        } catch (WxErrorException e) {
//            PtAssert.fail(e.getMessage());
//        }
//        return success(token);
//    }
//
//}
