package com.github.sd4324530.fastweixin.company.api;

import com.github.sd4324530.fastweixin.api.response.BaseResponse;
import com.github.sd4324530.fastweixin.company.api.config.QYAPIConfig;
import com.github.sd4324530.fastweixin.company.api.entity.QYAgent;
import com.github.sd4324530.fastweixin.company.api.enums.QYResultType;
import com.github.sd4324530.fastweixin.company.api.response.GetQYAgentInfoResponse;
import com.github.sd4324530.fastweixin.company.api.response.GetQYAgentListResponse;
import com.github.sd4324530.fastweixin.util.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 *  
 *  ====================================================================
 *  上海聚攒软件开发有限公司
 *  --------------------------------------------------------------------
 *  @author Nottyjay
 *  @version 1.0.beta
 *  ====================================================================
 */
public class QYAgentAPI extends QYBaseAPI {

    private static final Logger LOG = LoggerFactory.getLogger(QYAgentAPI.class);

    /**
     * 构造方法，设置apiConfig
     *
     * @param config 微信API配置对象
     */
    public QYAgentAPI(QYAPIConfig config) {
        super(config);
    }

    /**
     * 获取全部应用列表
     * @return
     */
    public GetQYAgentListResponse getAll(){
        GetQYAgentListResponse response;
        String url = BASE_API_URL + "cgi-bin/agent/list?access_token=#";
        BaseResponse r = executeGet(url);
        String jsonResult = isSuccess(r.getErrcode()) ? r.getErrmsg() : r.toJsonString();
        System.out.println(jsonResult);
        response = JSONUtil.toBean(jsonResult, GetQYAgentListResponse.class);
        return response;
    }

    /**
     * 获取应用信息
     * @param agentId 应用ID
     * @return
     */
    public GetQYAgentInfoResponse getInfo(String agentId){
        GetQYAgentInfoResponse response;
        String url = BASE_API_URL + "cgi-bin/agent/get?access_token=#&agentid=" + agentId;
        BaseResponse r = executeGet(url);
        String jsonResult = isSuccess(r.getErrcode()) ? r.getErrmsg() : r.toJsonString();
        response = JSONUtil.toBean(jsonResult, GetQYAgentInfoResponse.class);
        return response;
    }

    /**
     * 设置应用信息
     * @param agent 应用对象
     * @param mediaId 应用的logo
     * @return
     */
    public QYResultType create(QYAgent agent, String mediaId){
        String url = BASE_API_URL + "cgi-bin/agent/set?access_token=#";
        final Map<String, Object> params = new HashMap<String, Object>();
        params.put("agentid", agent.getAgentId());
        params.put("report_location_flag", String.valueOf(agent.getReportLocationFlag()));
        params.put("logo_mediaid", mediaId);
        params.put("name", agent.getName());
        params.put("description", agent.getDescription());
        params.put("redirect_domain", agent.getRedirectDomain());
        params.put("isreportuser", agent.getIsReportUser());
        params.put("isreportenter", agent.getIsReportEnter());
        BaseResponse response = executePost(url, JSONUtil.toJson(params));
        return QYResultType.get(response.getErrcode());
    }
}

@@ -1563,48 +1563,8 @@
 ();%0A
-        System.out.println(jsonResult);%0A
     
@@ -1629,32 +1629,32 @@
 esponse.class);%0A
+
         return r
@@ -2192,24 +2192,165 @@
    * %E8%AE%BE%E7%BD%AE%E5%BA%94%E7%94%A8%E4%BF%A1%E6%81%AF%0A
+     * -----------------------------------------------%0A     * %E8%AE%BE%E7%BD%AE%E5%BA%94%E7%94%A8%E4%BF%A1%E6%81%AF%E6%96%B9%E6%B3%95%E4%BD%BF%E7%94%A8%E6%96%B0%E7%9A%84update%E6%96%B9%E6%B3%95%E4%BB%A3%E6%9B%BF%E3%80%82%0A     * -----------------------------------------------%0A
      * @para
@@ -2407,32 +2407,48 @@
 @return%0A     */%0A
+    @Deprecated%0A
     public QYRes
@@ -3054,24 +3054,24 @@
 ortUser());%0A
-
         para
@@ -3257,11 +3257,349 @@
 );%0A    %7D
+%0A%0A    /**%0A     * %E6%96%B0%E7%9A%84%E8%AE%BE%E7%BD%AE%E5%BA%94%E7%94%A8%E4%BF%A1%E6%81%AF%0A     * @param params%0A     * @return%0A     */%0A    public QYResultType update(Map%3CString, Object%3E params)%7B%0A        String url = BASE_API_URL + %22cgi-bin/agent/set?access_token=#%22;%0A        BaseResponse response = executePost(url, JSONUtil.toJson(params));%0A        return QYResultType.get(response.getErrcode());%0A    %7D
 %0A%7D%0A

删除了一句输出语句。并新增了设置应用的方法