不嫌代码写的烂 可以参考下
https://github.com/ren2881971/WeChat
着急实现功能 没重构 ######
/**
* 微信授权
*
*
*/
public class CUserOauthWeixinRedirect extends ABaseCommand {
private static final String URL_OAUTH_ACCESS_TOKEN =
"https://api.weixin.qq.com/sns/oauth2/access_token";
private static final String URL_OAUTH_USER_INFO = "https://api.weixin.qq.com/sns/userinfo";
/** 状态:module0xxx010010 模块0xxx0识别ID*/
private String state;
/** 换取access_token票据 */
private String code;
String module;
String id;
String ip;
@Override
public void init() throws Exception {
state = getPara("state");
if (StrKit.isBlank(state)) {
throw new ArgException("状态不正确");
}
String[] moduleInfoArray = state.split(Define.WEIXIN_MODULE_OAUTH_SPLITER);
if (moduleInfoArray.length != 2) {
throw new ArgException("状态不正确");
}
module = moduleInfoArray[0];
if (!Define.validateWeixinModule(module)) {
throw new ArgException("模块不存在");
}
id = moduleInfoArray[1];
code = getPara("code");
Util.assertNotBlank(code, "code不能为空");
ip = "%";
}
@Override
public void doCommand(AResult r