11package me .chanjar .weixin .open .api .impl ;
22
3+ import cn .binarywang .wx .miniapp .api .WxMaService ;
4+ import cn .binarywang .wx .miniapp .bean .WxMaJscode2SessionResult ;
35import com .google .gson .JsonObject ;
4- import me .chanjar .weixin .common .bean .result .WxError ;
56import me .chanjar .weixin .common .exception .WxErrorException ;
67import me .chanjar .weixin .common .util .crypto .SHA1 ;
78import me .chanjar .weixin .common .util .http .URIUtil ;
3031 * @author <a href="https://github.com/007gzs">007</a>
3132 */
3233public class WxOpenComponentServiceImpl implements WxOpenComponentService {
34+
35+ private static final Map <String , WxMaService > WX_OPEN_MA_SERVICE_MAP = new Hashtable <>();
3336 private static final Map <String , WxMpService > WX_OPEN_MP_SERVICE_MAP = new Hashtable <>();
37+
3438 protected final Logger log = LoggerFactory .getLogger (this .getClass ());
3539 private WxOpenService wxOpenService ;
3640
@@ -54,6 +58,20 @@ public WxMpService getWxMpServiceByAppid(String appId) {
5458 return wxMpService ;
5559 }
5660
61+ @ Override
62+ public WxMaService getWxMaServiceByAppid (String appId ) {
63+ WxMaService wxMaService = WX_OPEN_MA_SERVICE_MAP .get (appId );
64+ if (wxMaService == null ) {
65+ synchronized (WX_OPEN_MA_SERVICE_MAP ) {
66+ wxMaService = WX_OPEN_MA_SERVICE_MAP .get (appId );
67+ if (wxMaService == null ) {
68+ wxMaService = new WxOpenMaServiceImpl (this , appId , getWxOpenConfigStorage ().getWxMaConfig (appId ));
69+ WX_OPEN_MA_SERVICE_MAP .put (appId , wxMaService );
70+ }
71+ }
72+ }
73+ return wxMaService ;
74+ }
5775 public WxOpenService getWxOpenService () {
5876 return wxOpenService ;
5977 }
@@ -137,7 +155,7 @@ public String route(final WxOpenXmlMessage wxMessage) throws WxErrorException {
137155 }
138156 return "success" ;
139157 }
140- return null ;
158+ return "" ;
141159 }
142160
143161 @ Override
@@ -169,14 +187,13 @@ public WxOpenAuthorizerOptionResult getAuthorizerOption(String authorizerAppid,
169187 }
170188
171189 @ Override
172- public WxError setAuthorizerOption (String authorizerAppid , String optionName , String optionValue ) throws WxErrorException {
190+ public void setAuthorizerOption (String authorizerAppid , String optionName , String optionValue ) throws WxErrorException {
173191 JsonObject jsonObject = new JsonObject ();
174192 jsonObject .addProperty ("component_appid" , getWxOpenConfigStorage ().getComponentAppId ());
175193 jsonObject .addProperty ("authorizer_appid" , authorizerAppid );
176194 jsonObject .addProperty ("option_name" , optionName );
177195 jsonObject .addProperty ("option_value" , optionValue );
178- String responseContent = post (API_SET_AUTHORIZER_OPTION_URL , jsonObject .toString ());
179- return WxGsonBuilder .create ().fromJson (responseContent , WxError .class );
196+ post (API_SET_AUTHORIZER_OPTION_URL , jsonObject .toString ());
180197 }
181198
182199 @ Override
@@ -220,4 +237,11 @@ public String oauth2buildAuthorizationUrl(String appId, String redirectURI, Stri
220237 appId , URIUtil .encodeURIComponent (redirectURI ), scope , StringUtils .trimToEmpty (state ), getWxOpenConfigStorage ().getComponentAppId ());
221238 }
222239
240+ @ Override
241+ public WxMaJscode2SessionResult miniappJscode2Session (String appid , String jsCode , String appId ) throws WxErrorException {
242+ String url = String .format (MINIAPP_JSCODE_2_SESSION , appId , jsCode , getWxOpenConfigStorage ().getComponentAppId ());
243+ String responseContent = get (url );
244+ return WxMaJscode2SessionResult .fromJson (responseContent );
245+ }
246+
223247}
0 commit comments