package io.github.elkan1788.mpsdk4j.vo;

import java.util.Map;

import org.nutz.json.Json;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import io.github.elkan1788.mpsdk4j.util.ConfigReader;

/**
 * 封装微信api返回结果, 输出实体类
 * 
 * @author 凡梦星尘(elkan1788@gmail.com)
 * @since 2.0
 */
@SuppressWarnings("unchecked")
public class ApiResult {

    private static final Log log = Logs.get();

    private static ConfigReader _cr;

    static {
        _cr = new ConfigReader("/ErrorCode.properties");
    }

    private Map<String, Object> content;
    private String json;
    private Integer errCode;
    private String errMsg;
    private String errCNMsg;

    public ApiResult(String json) {
        this.json = json;
        this.content = Json.fromJson(Map.class, json);
        this.errCode = (Integer) this.content.get("errcode");
        this.errMsg = (String) this.content.get("errmsg");
        this.errCNMsg = this.errCode == null ? "请求成功." : _cr.get(String.valueOf(this.errCode));

        if (log.isInfoEnabled()) {
            log.infof("Wechat api result: %s", json);
            log.infof("%s", this.getErrCNMsg());
        }
    }

    public static ApiResult create(String json) {
        return new ApiResult(json);
    }

    public Object get(String key) {
        return content.get(key);
    }

    public Map<String, Object> getContent() {
        return content;
    }

    public String getJson() {
        return json;
    }

    public Integer getErrCode() {
        return this.errCode;
    }

    public String getErrMsg() {
        return this.errMsg == null ? "Unknow Error!" : this.errMsg;
    }

    public String getErrCNMsg() {
        return this.errCNMsg == null ? "未知错误!" : this.errCNMsg;
    }

    public boolean isSuccess() {
        return (this.errCode == null || this.errCode.intValue() == 0);
    }

}

@@ -321,18 +321,18 @@
  class A
-pi
+PI
 Result %7B
@@ -656,26 +656,26 @@
     public A
-pi
+PI
 Result(Strin
@@ -1157,18 +1157,18 @@
 static A
-pi
+PI
 Result c
@@ -1208,18 +1208,18 @@
 rn new A
-pi
+PI
 Result(j
@@ -1753,24 +1753,68 @@
 Success() %7B%0A
+        // TODO 46003%E8%A1%A8%E7%A4%BA%E4%B8%8D%E5%AD%98%E5%9C%A8%E8%8F%9C%E5%8D%95%E6%95%B0%E6%8D%AE,%E7%AE%97%E5%B1%9E%E4%BA%8E%E5%90%88%E6%B3%95,%E4%B8%8D%E5%BA%94%E6%8A%9B%E5%87%BA%E5%BC%82%E5%B8%B8%0A
         retu
@@ -1837,16 +1837,32 @@
  == null
+%0A               
  %7C%7C this
@@ -1885,16 +1885,68 @@
 e() == 0
+%0A                %7C%7C this.errCode.intValue() == 46003
 );%0A    %7D

重命名APIResult,增加自定义菜单输出46003成功返回