package com.fengqi.wechat.controller;


import com.fengqi.wechat.controller.base.AbstractWechatController;
import com.fengqi.wechat.entity.MessageConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 服务号api
 */
@RestController
@Slf4j
@RequestMapping("/api/subscribe")
public class ApiSubscribeController extends AbstractWechatController {


    private class ServiceRedisKey implements RedisKey {

        /**
         * 订阅公众号的key
         *
         * @return
         */
        @Override
        public String getSubscribeKey() {
            return MessageConstant.REDIS_SUBSCRIBE_MESSAGE.replace("${type}","subscribe");
        }

        /**
         * 自动回复的key
         *
         * @return
         */
        @Override
        public String getMessageKey() {
            return MessageConstant.REDIS_MESSAGE.replace("${type}","subscribe");
        }
    }

    @Value("${wechat.subscribe.appid}")
    private String appid;

    @Value("${wechat.subscribe.secret}")
    private String secret;


    @Override
    protected String getAccessTokenRedisKey() {
        return MessageConstant.REDIS_ACCESS_TOKEN.replace("${type}","subscribe");
    }

    @Override
    protected String getAppId() {
        return this.appid;
    }

    @Override
    protected String getSecret() {
        return this.secret;
    }

    @Override
    protected RedisKey getRedisKey() {
        return new ServiceRedisKey();
    }
}
