package com.platform.api;

import com.platform.annotation.IgnoreAuth;
import com.platform.service.WechatService;
import com.platform.util.ApiBaseAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/wechat")
public class ApiWechatController extends ApiBaseAction {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private WechatService wechatService;

    @IgnoreAuth
    @PostMapping("/generateMicroAppCode")
    public Object generateMicroAppCode(@RequestBody Map<String,String> param){
        String scene = param.get("scene");
        String page = param.get("page");
        logger.info("generateMicroAppCode params, scene:{},page:{}",scene,page);
        if(ObjectUtils.isEmpty(scene)){
            return toResponsFail("参数有误！");
        }
        try{
            String result = wechatService.generateMicroAppCode(scene,page);
            return toResponsSuccess(result);
        }catch (Exception e){
            e.printStackTrace();
            return toResponsFail(ObjectUtils.isEmpty(e.getMessage()) ? "生成失败！" : e.getMessage());
        }

    }

}
