1
1
package me .chanjar .weixin .open .api .impl ;
2
2
3
+ import cn .binarywang .wx .miniapp .api .WxMaService ;
4
+ import cn .binarywang .wx .miniapp .bean .WxMaJscode2SessionResult ;
3
5
import com .google .gson .JsonObject ;
4
- import me .chanjar .weixin .common .bean .result .WxError ;
5
6
import me .chanjar .weixin .common .exception .WxErrorException ;
6
7
import me .chanjar .weixin .common .util .crypto .SHA1 ;
7
8
import me .chanjar .weixin .common .util .http .URIUtil ;
30
31
* @author <a href="https://github.com/007gzs">007</a>
31
32
*/
32
33
public class WxOpenComponentServiceImpl implements WxOpenComponentService {
34
+
35
+ private static final Map <String , WxMaService > WX_OPEN_MA_SERVICE_MAP = new Hashtable <>();
33
36
private static final Map <String , WxMpService > WX_OPEN_MP_SERVICE_MAP = new Hashtable <>();
37
+
34
38
protected final Logger log = LoggerFactory .getLogger (this .getClass ());
35
39
private WxOpenService wxOpenService ;
36
40
@@ -54,6 +58,20 @@ public WxMpService getWxMpServiceByAppid(String appId) {
54
58
return wxMpService ;
55
59
}
56
60
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
+ }
57
75
public WxOpenService getWxOpenService () {
58
76
return wxOpenService ;
59
77
}
@@ -137,7 +155,7 @@ public String route(final WxOpenXmlMessage wxMessage) throws WxErrorException {
137
155
}
138
156
return "success" ;
139
157
}
140
- return null ;
158
+ return "" ;
141
159
}
142
160
143
161
@ Override
@@ -169,14 +187,13 @@ public WxOpenAuthorizerOptionResult getAuthorizerOption(String authorizerAppid,
169
187
}
170
188
171
189
@ 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 {
173
191
JsonObject jsonObject = new JsonObject ();
174
192
jsonObject .addProperty ("component_appid" , getWxOpenConfigStorage ().getComponentAppId ());
175
193
jsonObject .addProperty ("authorizer_appid" , authorizerAppid );
176
194
jsonObject .addProperty ("option_name" , optionName );
177
195
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 ());
180
197
}
181
198
182
199
@ Override
@@ -220,4 +237,11 @@ public String oauth2buildAuthorizationUrl(String appId, String redirectURI, Stri
220
237
appId , URIUtil .encodeURIComponent (redirectURI ), scope , StringUtils .trimToEmpty (state ), getWxOpenConfigStorage ().getComponentAppId ());
221
238
}
222
239
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
+
223
247
}
0 commit comments