2
0
mirror of https://gitee.com/hotlcc/wechat4j.git synced 2025-06-08 03:24:09 +08:00

提交代码

This commit is contained in:
hotlcc 2018-07-25 15:46:34 +08:00
parent 5db685323f
commit c50e37415c
4 changed files with 29 additions and 24 deletions

View File

@ -1050,7 +1050,7 @@ public class Wechat {
* @return * @return
*/ */
public JSONObject sendText(String content, String toUserName) { public JSONObject sendText(String content, String toUserName) {
BaseRequest BaseRequest = new BaseRequest(wxsid, skey, wxuin); BaseRequest baseRequest = new BaseRequest(wxsid, skey, wxuin);
String msgId = WechatUtil.createMsgId(); String msgId = WechatUtil.createMsgId();
String loginUserName = getLoginUserName(false); String loginUserName = getLoginUserName(false);
@ -1066,7 +1066,7 @@ public class Wechat {
} }
message.setType(MsgTypeEnum.TEXT_MSG.getCode()); message.setType(MsgTypeEnum.TEXT_MSG.getCode());
JSONObject result = webWeixinApi.sendMsg(httpClient, passTicket, BaseRequest, message); JSONObject result = webWeixinApi.sendMsg(httpClient, passTicket, baseRequest, message);
return result; return result;
} }

View File

@ -528,7 +528,7 @@ public class WebWeixinApi {
*/ */
public JSONObject sendMsg(HttpClient httpClient, public JSONObject sendMsg(HttpClient httpClient,
String passticket, String passticket,
BaseRequest BaseRequest, BaseRequest baseRequest,
WxMessage message) { WxMessage message) {
try { try {
String url = new ST(PropertiesUtil.getProperty("webwx-url.webwxsendmsg_url")) String url = new ST(PropertiesUtil.getProperty("webwx-url.webwxsendmsg_url"))
@ -539,7 +539,7 @@ public class WebWeixinApi {
httpPost.setHeader("Content-type", ContentType.APPLICATION_JSON.toString()); httpPost.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
JSONObject paramJson = new JSONObject(); JSONObject paramJson = new JSONObject();
paramJson.put("BaseRequest", BaseRequest); paramJson.put("BaseRequest", baseRequest);
paramJson.put("Msg", message); paramJson.put("Msg", message);
paramJson.put("Scene", 0); paramJson.put("Scene", 0);
System.out.println(paramJson.toJSONString()); System.out.println(paramJson.toJSONString());

View File

@ -24,7 +24,7 @@ public class WxMessage {
} }
public void setClientMsgId(String clientMsgId) { public void setClientMsgId(String clientMsgId) {
clientMsgId = clientMsgId; this.clientMsgId = clientMsgId;
} }
public String getContent() { public String getContent() {
@ -32,7 +32,7 @@ public class WxMessage {
} }
public void setContent(String content) { public void setContent(String content) {
content = content; this.content = content;
} }
public String getFromUserName() { public String getFromUserName() {
@ -40,7 +40,7 @@ public class WxMessage {
} }
public void setFromUserName(String fromUserName) { public void setFromUserName(String fromUserName) {
fromUserName = fromUserName; this.fromUserName = fromUserName;
} }
public String getLocalID() { public String getLocalID() {
@ -48,7 +48,7 @@ public class WxMessage {
} }
public void setLocalID(String localID) { public void setLocalID(String localID) {
localID = localID; this.localID = localID;
} }
public String getToUserName() { public String getToUserName() {
@ -56,7 +56,7 @@ public class WxMessage {
} }
public void setToUserName(String toUserName) { public void setToUserName(String toUserName) {
toUserName = toUserName; this.toUserName = toUserName;
} }
public Integer getType() { public Integer getType() {

View File

@ -4,23 +4,28 @@ import com.hotlcc.wechat4j.api.WebWeixinApi;
import com.hotlcc.wechat4j.handler.ReceivedMsgHandler; import com.hotlcc.wechat4j.handler.ReceivedMsgHandler;
import com.hotlcc.wechat4j.model.ReceivedMsg; import com.hotlcc.wechat4j.model.ReceivedMsg;
import com.hotlcc.wechat4j.model.UserInfo; import com.hotlcc.wechat4j.model.UserInfo;
import com.hotlcc.wechat4j.model.WxMessage;
public class TestClass2 { public class TestClass2 {
public static void main(String[] args) { public static void main(String[] args) {
WebWeixinApi api = new WebWeixinApi(); // WebWeixinApi api = new WebWeixinApi();
Wechat wechat = new Wechat(); // Wechat wechat = new Wechat();
wechat.setWebWeixinApi(api); // wechat.setWebWeixinApi(api);
wechat.addReceivedMsgHandler(new ReceivedMsgHandler() { // wechat.addReceivedMsgHandler(new ReceivedMsgHandler() {
@Override // @Override
public void handleAllType(Wechat wechat, ReceivedMsg msg) { // public void handleAllType(Wechat wechat, ReceivedMsg msg) {
UserInfo contact = wechat.getContactByUserName(false, msg.getFromUserName()); // UserInfo contact = wechat.getContactByUserName(false, msg.getFromUserName());
System.out.println(contact.getRemarkName() + "" + msg.getContent()); // System.out.println(contact.getRemarkName() + "" + msg.getContent());
if ("李国栋".equals(contact.getRemarkName())) { // if ("李国栋".equals(contact.getRemarkName())) {
JSONObject result = wechat.sendText("你的消息收到了", contact.getUserName()); // JSONObject result = wechat.sendText("你的消息收到了", contact.getUserName());
System.out.println(result); // System.out.println(result);
} // }
} // }
}); // });
wechat.autoLogin(); // wechat.autoLogin();
WxMessage message=new WxMessage();
message.setToUserName("1");
message.setType(1);
System.out.println(JSONObject.toJSONString(message));
} }
} }