WxOpenService.java 4.2 KB
package org.theyeasy.weixin.service;


import org.apache.http.HttpHost; 
 
import org.theyeasy.weixin.model.WxOpenConfigStorage;
import org.theyeasy.weixin.model.WxOpenQueryAuthResult;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;



public interface WxOpenService {
	
	/**
	 * 获取授权公众号操作对象   系统初始化的时候调用
	 * @param appId  授权公众号appId
	 * @param authorizerRefreshToken  刷新token
	 * @return
	 * @throws WxErrorException
	 */
	public  WxMpService initWxMpService(String appId,String authorizerRefreshToken) throws WxErrorException;
	
	/**
	 *  获取授权公众号操作对象  操作公众号对象
	 * @param appId  授权公众号appId
	 * @throws WxErrorException
	 */
	public  WxMpService getWxMpService(String appId) throws WxErrorException;
	
	
	public void setWxOpenConfigStorage(WxOpenConfigStorage wxOpenConfigStorage) ;


	public WxOpenConfigStorage getWxOpenConfigStorage();
	
	
	
	
	/**
	 * 获取预授权码。预授权码用于公众号授权时的第三方平台方安全验证。
	 * @return 返回预授权码
	 * @throws WxErrorException
	 */
	String getPreAuthCode() throws WxErrorException;
	
	/**
	   * <pre>
	   * 获取PreAuthCode,本方法线程安全
	   * 且在多线程同时刷新时只刷新一次
	   *
	   * 程序员在非必要情况下尽量不要主动调用此方法
	   * </pre>
	   *
	   * @param forceRefresh 强制刷新
	   */
	public String getPreAuthCode(boolean forceRefresh) throws WxErrorException;
	
	/**
	 * 获取授权方的帐号基本信息
	 * @return
	 * @throws WxErrorException
	 */
	WxOpenQueryAuthResult getApiQueryAuth(String authorizationCode) throws WxErrorException;
	
	/**
	 * 获取授权方的帐号基本信息
	 * @return
	 * @throws WxErrorException
	 */
	String getApiGetAuthorizerInfo(String authorizationCode,int merchantid) throws WxErrorException;
	
	
	
	/**
	   * 获取access_token, 不强制刷新access_token
	   *
	   * @see #getAccessToken(boolean)
	   */
	  String getAccessToken() throws WxErrorException;

	  /**
	   * <pre>
	   * 获取access_token,本方法线程安全
	   * 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限
	   *
	   * 另:本service的所有方法都会在access_token过期是调用此方法
	   *
	   * 程序员在非必要情况下尽量不要主动调用此方法
	   *
	   * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183&token=&lang=zh_CN
	   * </pre>
	   *
	   * @param forceRefresh 强制刷新
	   */
	  String getAccessToken(boolean forceRefresh) throws WxErrorException;
	  
	  /**
	   * 获取代理对象
	   */
	  HttpHost getHttpProxy();
	  
	  /**
	   * 获取预授权网址
	   * @return
	   */
	  String getOauth2buildAuthorizationUrl() throws WxErrorException;
	  /**
	   * 获取预授权网址
	   * redirectUri 回调地址
	   * @return
	   */
	  public String getOauth2buildAuthorizationUrl(String redirectUri) throws WxErrorException;
	  
	  
	
	  <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
	  
	  /**
	   * <pre>
	   * 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试
	   * 默认:1000ms
	   * </pre>
	   */
	  void setRetrySleepMillis(int retrySleepMillis);
	  
	  /**
	   * <pre>
	   * 设置当微信系统响应系统繁忙时,最大重试次数
	   * 默认:5次
	   * </pre>
	   */
	  void setMaxRetryTimes(int maxRetryTimes);
	  
	  
	  /**
	   * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求
	   */
	  String post(String url, String postData) throws WxErrorException;
	  
	  
	  /**
	   * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
	   */
	  String get(String url, String queryParam) throws WxErrorException;
	  
	  
	  
	  public WxMpXmlOutMessage route(WxMpXmlMessage message,String appId);
	  
	
}