| | |
| | | import java.io.InputStream;
|
| | |
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.entity.wx.WXAPPInfo;
|
| | |
|
| | | import com.aliyun.openservices.shade.io.netty.util.internal.StringUtil;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | |
| | | return HttpUtil.postForInputstream(url, data.toString());
|
| | | }
|
| | |
|
| | | public static String getOpenId(WXAPPInfo app, String code) {
|
| | | try {
|
| | | String url = String.format(
|
| | | "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code",
|
| | | app.getAppId(), app.getAppSecret(), code);
|
| | | String result = HttpUtil.get(url);
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | String openId = json.optString("openid");
|
| | | if (!StringUtil.isNullOrEmpty(openId)) {
|
| | | return openId;
|
| | | }
|
| | | } catch (Exception e) {
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|