Skip to content

Commit

Permalink
Merge pull request #21 from Armink-Tech/master
Browse files Browse the repository at this point in the history
【完善】新用户登录异常处理
  • Loading branch information
meteorOSS authored Mar 3, 2024
2 parents d71a8cc + 33cd7a6 commit d080487
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
49 changes: 30 additions & 19 deletions src/main/java/com/meteor/wechatbc/entitiy/session/BaseRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Data;
import lombok.ToString;
import okhttp3.Cookie;
import org.apache.logging.log4j.LogManager;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Expand Down Expand Up @@ -49,26 +50,36 @@ public BaseRequest(String xmlData){
try {
builder = factory.newDocumentBuilder();
Document document = builder.parse(new ByteArrayInputStream(xmlData.getBytes()));
NodeList skeyList = document.getElementsByTagName("skey");
if (skeyList.getLength() > 0) {
Element skeyElement = (Element) skeyList.item(0);
this.skey = skeyElement.getTextContent();;
}
NodeList wxsidList = document.getElementsByTagName("wxsid");
if (wxsidList.getLength() > 0) {
Element wxsidElement = (Element) wxsidList.item(0);
this.sid = wxsidElement.getTextContent();
}
NodeList wxuniList = document.getElementsByTagName("wxuin");
if (wxsidList.getLength() > 0) {
Element wxuniElement = (Element) wxuniList.item(0);
this.uin = wxuniElement.getTextContent();
}
NodeList passTicketList = document.getElementsByTagName("pass_ticket");
if (passTicketList.getLength() > 0) {
Element passTicketElement = (Element) passTicketList.item(0);
this.passTicket = passTicketElement.getTextContent();

Element errorElement = (Element) document.getElementsByTagName("error").item(0);
if (errorElement == null) {
NodeList skeyList = document.getElementsByTagName("skey");
if (skeyList.getLength() > 0) {
Element skeyElement = (Element) skeyList.item(0);
this.skey = skeyElement.getTextContent();;
}
NodeList wxsidList = document.getElementsByTagName("wxsid");
if (wxsidList.getLength() > 0) {
Element wxsidElement = (Element) wxsidList.item(0);
this.sid = wxsidElement.getTextContent();
}
NodeList wxuniList = document.getElementsByTagName("wxuin");
if (wxsidList.getLength() > 0) {
Element wxuniElement = (Element) wxuniList.item(0);
this.uin = wxuniElement.getTextContent();
}
NodeList passTicketList = document.getElementsByTagName("pass_ticket");
if (passTicketList.getLength() > 0) {
Element passTicketElement = (Element) passTicketList.item(0);
this.passTicket = passTicketElement.getTextContent();
}
} else {
String ret = errorElement.getElementsByTagName("ret").item(0).getTextContent();
String message = errorElement.getElementsByTagName("message").item(0).getTextContent();
LogManager.getLogger("BASE-REQUEST").error("登录失败:" + message + " CODE: " + ret);
throw new RuntimeException();
}

} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@ private BaseRequest getLoginInfo(QRCodeResponse qrCodeResponse) {
// 设置登录设备ID
baseRequest.setDeviceId(BaseConfig.getDeviceId());

Cookie ck = cookies.get(0);
String baseDomain = "wx.qq.com";
if (!cookies.isEmpty()) {
Cookie ck = cookies.get(0);
baseDomain = ck.domain();
}

// 获取cookie的 domain 所属域名
URL.setBASE_URL(new HttpUrl.Builder()
.scheme("https")
.host(ck.domain())
.host(baseDomain)
.build());

for (Cookie cookie : cookies) {
Expand Down

0 comments on commit d080487

Please sign in to comment.