个人申请的订阅号,怎样每天自动推送一条群发信息?

逍遥的小贝 发布于 2014/04/02 10:29
阅读 8K+
收藏 1

@夏悸 你好,想跟你请教个问题:个人申请的订阅号,怎样每天自动推送一条群发信息?

从网上找了一下,大概都是用httpclient包里的相关类模拟登录网页版公众平台之后发送,请问你是否有相关代码?试了别人写的代码,不是给出的微信官方网址错误,就是发送信息的格式不正确。

加载中
0
秋阳
秋阳

帮顶~顺便同求~

0
夏悸
夏悸

没有这种接口。。。而且各种的模拟httpclient都是不靠谱的。。。

微信在这块防垃圾信息这块还是限制很严格的

帖子列表
帖子列表
能说说微信怎么防垃圾推送么 是哪里会一直变来变去 还是怎样
0
54mark
54mark

没有主动推的接口~只有被动接口

0
吴小华
吴小华

认证300元就有了

0
hphper
hphper

普通的订阅号没有,要么服务号,要么认证的订阅号

0
逍遥的小贝
逍遥的小贝

我已经做成功了,需要的联系我。

Timco
Timco
能发给我学习学习么?邮箱 pqing112358@gmail.com
0
逍遥的小贝
逍遥的小贝

登录的返回信息格式:

public class Login {
	public class Base_resp{
		private int ret;
		private String err_msg;
		public int getRet() {
			return ret;
		}
		public void setRet(int ret) {
			this.ret = ret;
		}
		public String getErr_msg() {
			return err_msg;
		}
		public void setErr_msg(String err_msg) {
			this.err_msg = err_msg;
		}		
	}
	private Base_resp base_resp;
	private String redirect_url;
	public Base_resp getBase_resp() {
		return base_resp;
	}
	public void setBase_resp(Base_resp base_resp) {
		this.base_resp = base_resp;
	}
	public String getRedirect_url() {
		return redirect_url;
	}
	public void setRedirect_url(String redirect_url) {
		this.redirect_url = redirect_url;
	}	
}



0
逍遥的小贝
逍遥的小贝

登录的代码如下:

/**
	 * 发送登录信息,记录cookie,登录状态,token等信息
	 * 
	 * @return
	 */
	private boolean _login() {
		try {
			//
			System.setProperty("jsse.enableSNIExtension", "false");
			ProtocolSocketFactory fcty = new MySecureProtocolSocketFactory();
			Protocol.registerProtocol("https", new Protocol("https", fcty, 443));
			//
			PostMethod post = new PostMethod(LOGIN_URL);//
			post.setRequestHeader(USER_AGENT_H, USER_AGENT);
			post.setRequestHeader(REFERER_H, HOST);
			post.setRequestHeader("Accept",
					"application/json, text/javascript, */*; q=0.01");
			post.setRequestHeader("Accept-Encoding", "gzip, deflate");
			post.setRequestHeader("Accept-Language",
					"zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
			post.setRequestHeader("Cache-Control", "no-cache");
			post.setRequestHeader("Connection", "keep-alive");

			post.setRequestHeader("Content-Type",
					"application/x-www-form-urlencoded; charset=UTF-8");
			post.setRequestHeader("Host", "mp.weixin.qq.com");
			post.setRequestHeader("Pragma", "no-cache");
			post.setRequestHeader("X-Requested-With", "XMLHttpRequest");

			NameValuePair[] params = new NameValuePair[] {
					new NameValuePair("username", this.loginUser),
					new NameValuePair("pwd", DigestUtils.md5Hex(this.loginPwd
							.getBytes())), new NameValuePair("imgcode", ""),
					new NameValuePair("f", "json") };// ,
			//
			post.setQueryString(params);
			int status = client.executeMethod(post);

			if (status == HttpStatus.SC_OK) {
				String ret = post.getResponseBodyAsString();
				
				Login retcode = JSON.parseObject(ret, Login.class);
				if (retcode.getBase_resp().getRet() == 0 && retcode.getBase_resp().getErr_msg().equals("ok")) {//http协议返回302表示已经重定向
					this.cookies = client.getState().getCookies();
					StringBuffer cookie = new StringBuffer();
					for (Cookie c : client.getState().getCookies()) {
						cookie.append(c.getName()).append("=")
								.append(c.getValue()).append(";");
					}
					this.cookiestr = cookie.toString();
					this.isLogin = true;
					this.token = getToken(retcode.getRedirect_url());					
					return true;
				}
				int errCode = retcode.getBase_resp().getRet();
				
				this.loginErrCode = errCode;
				switch (errCode) {

				case -1:
					this.loginErrMsg = "系统错误";
					return false;
				case -2:
					this.loginErrMsg = "帐号或密码错误";
					return false;
				case -3:
					this.loginErrMsg = "密码错误";
					return false;
				case -4:
					this.loginErrMsg = "不存在该帐户";
					return false;
				case -5:
					this.loginErrMsg = "访问受限";
					return false;
				case -6:
					this.loginErrMsg = "需要输入验证码";
					return false;
				case -7:
					this.loginErrMsg = "此帐号已绑定私人微信号,不可用于公众平台登录";
					return false;
				case -8:
					this.loginErrMsg = "邮箱已存在";
					return false;
				case -32:
					this.loginErrMsg = "验证码输入错误";
					return false;
				case -200:
					this.loginErrMsg = "因频繁提交虚假资料,该帐号被拒绝登录";
					return false;
				case -94:
					this.loginErrMsg = "请使用邮箱登陆";
					return false;
				case 10:
					this.loginErrMsg = "该公众会议号已经过期,无法再登录使用";
					return false;
				case 65201:
				case 65202:
					this.loginErrMsg = "成功登陆,正在跳转...";
					return true;
				case 0:
					this.loginErrMsg = "成功登陆,正在跳转...";
					return true;
				default:
					this.loginErrMsg = "未知的返回";
					return false;
				}
			}
		} catch (Exception e) {
			String info = "【登录失败】【发生异常:" + e.getMessage() + "】";
			System.err.println(info);
			log.debug(info);
			log.info(info);
			return false;
		}
		return false;
	}



0
逍遥的小贝
逍遥的小贝

群发的代码

/**
	 * 
	 * 群发消息
	 * <p>
	 * 返回码说明<br>
	 * 0:发送成功<br>
	 * 64004:今天的群发数量已到,无法群发<br>
	 * -20000:请求被禁止,请仔细检查token是否合法<br>
	 * </p>
	 * <p>
	 * 可通过msgSendCode取得发送状态码
	 * </p>
	 * 
	 * 
	 */
	/**
	 * @param form
	 * @param type
	 * @return
	 */
	public boolean msgSend(MsgForm form, MsgType type) {
		try {
			if (!this.isLogin) {
				this._login();
			}
			if (this.isLogin) {
				form.setToken(this.token);
				//System.out.println("this.token======"+this.token);
				//=====================
				System.setProperty("jsse.enableSNIExtension", "false");
				ProtocolSocketFactory fcty = new MySecureProtocolSocketFactory();
				Protocol.registerProtocol("https", new Protocol("https", fcty,
						443));
				//=====================
				PostMethod post = new PostMethod(POST_MSG);
				post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
				post.setRequestHeader(USER_AGENT_H, USER_AGENT);
				post.setRequestHeader(REFERER_H, INDEX_URL);
				post.setRequestHeader("Cookie", this.cookiestr);
				//System.out.println("this.cookiestr======"+this.cookiestr);
				post.setRequestHeader("Accept",
						"application/json, text/javascript, */*; q=0.01");
				post.setRequestHeader("Accept-Encoding", "gzip, deflate");
				post.setRequestHeader("Accept-Language",
						"zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
				post.setRequestHeader("Cache-Control", "no-cache");
				post.setRequestHeader("Connection", "keep-alive");
				post.setRequestHeader("Content-Type",
						"application/x-www-form-urlencoded; charset=UTF-8");
				post.setRequestHeader("Host", "mp.weixin.qq.com");
				post.setRequestHeader("Pragma", "no-cache");
				post.setRequestHeader("X-Requested-With", "XMLHttpRequest");
				NameValuePair[] params = null;
				Part[] parts = null;
				switch (type) {
				case TEXT:
					params = new NameValuePair[] {
							new NameValuePair("type", form.getType()),
							new NameValuePair("content", form.getContent()),
							new NameValuePair("error", form.getError()),
							new NameValuePair("imgcode", form.getImgcode()),
							new NameValuePair("needcomment", form.getNeedcomment()),
							new NameValuePair("groupid", form.getGroupid()),
							new NameValuePair("sex", form.getSex()),
							new NameValuePair("country", form.getCountry()),							
							new NameValuePair("city", form.getCity()),
							new NameValuePair("province", form.getProvince()),
							new NameValuePair("synctxweibo", form.getSynctxweibo()),
							new NameValuePair("synctxnews", form.getSynctxnews()),
							new NameValuePair("token", this.token),
							new NameValuePair("ajax", form.getAjax()),
							new NameValuePair("t", "ajax-response") };
					break;
				case IMAGE_TEXT:
					ImgTextMsgList list = this.getImgTextMsgList();
					List<ImgTextMsgList.ImgTextMsg> imgTextMsgs = list
							.getList();
					if (null != imgTextMsgs && !imgTextMsgs.isEmpty()) {
						ImgTextMsgList.ImgTextMsg imgTextMsg = imgTextMsgs
								.get(0);
						if (null != imgTextMsg) {
							form.setAppmsgid(imgTextMsg.getAppId());
							form.setFid(imgTextMsg.getAppId());
						}
					}
					if (StringUtils.isBlank(form.getAppmsgid())
							|| StringUtils.isBlank(form.getFid())) {
						this.msgSendMsg = "参数错误:appmsgid为空";
						return false;
					}
					parts = new Part[] {
							new StringPart("fid", form.getFid(), "UTF-8"),
							new StringPart("appmsgid", form.getAppmsgid(),
									"UTF-8"),
							new StringPart("type", MsgType.IMAGE_TEXT.getType()
									+ ""),
							new StringPart("error", form.getError()),
							new StringPart("needcomment", form.getNeedcomment()),
							new StringPart("groupid", form.getGroupid()),
							new StringPart("sex", form.getSex()),
							new StringPart("country", form.getCountry()),
							new StringPart("province", form.getProvince()),
							new StringPart("city", form.getCity()),
							new StringPart("token", form.getToken()),
							new StringPart("ajax", form.getAjax()),
							new StringPart("t", "ajax-response") };
					break;
				default:
					parts = new Part[] {
							new StringPart("content", form.getContent(),
									"UTF-8"),
							new StringPart("type", form.getType()),
							new StringPart("error", form.getError()),
							new StringPart("needcomment", form.getNeedcomment()),
							new StringPart("groupid", form.getGroupid()),
							new StringPart("sex", form.getSex()),
							new StringPart("country", form.getCountry()),
							new StringPart("province", form.getProvince()),
							new StringPart("city", form.getCity()),
							new StringPart("token", form.getToken()),
							new StringPart("ajax", form.getAjax()),
							new StringPart("t", "ajax-response") };

					break;
				}
				post.setRequestBody(params);
				//RequestEntity entity = new MultipartRequestEntity(parts,post.getParams());
				//post.setRequestEntity(entity);
				int status;
				status = client.executeMethod(post);
				if (status == HttpStatus.SC_OK) {
					String text = post.getResponseBodyAsString();
					//System.out.println("11..text========="+text);
					try {
						MsgJson ret = JSON.parseObject(text, MsgJson.class);
						this.msgSendCode = ret.getRet();
						switch (this.msgSendCode) {
						case 0:
							this.msgSendMsg = "发送成功";
							return true;
						case -2:
							this.msgSendMsg = "参数错误,请仔细检查";
							return false;
						case 64004:
							this.msgSendMsg = "今天的群发数量已到,无法群发";
							return false;
						case -20000:
							this.msgSendMsg = "请求被禁止,请仔细检查token是否合法";
							return false;
						default:
							this.msgSendMsg = "未知错误!";
							return false;
						}
					} catch (Exception e) {
						String info = "【群发信息失败】【解析json错误】" + e.getMessage()
								+ "\n\t【文本:】\n\t" + text;
						System.err.println(info);
						log.debug(info);
						log.info(info);
						return false;
					}
				}
			}
		} catch (Exception e) {
			String info = "【群发信息失败】" + e.getMessage();
			System.err.println(info);
			log.debug(info);
			log.info(info);
			return false;
		}
		return false;
	}



0
逍遥的小贝
逍遥的小贝
不好使了,又变了,郁闷Ing
返回顶部
顶部