JFinal weixin开发问题

andying 发布于 2016/04/03 02:12
阅读 687
收藏 0

@JFinal 你好,想跟你请教个问题:

我照着weixin demo集成到了实际环境中:

http://test.duapp.com/weixin ,发布可以运行,

发送help,奇怪的是微信公众号没有响应回信息(我用的是私人订阅号公众平台测试帐号进行测试

调试输出信息如下,

#----------processInTextMsg------------------
#server received char is :help
#begin to process the msg -----
如果发送中文字符"你好":中文变成??

#----------processInTextMsg------------------
#server received char is :??
#begin to process the msg -----

String outMsgXml1 = OutMsgXmlBuilder.build(outMsg);
System.out.println(outMsgXml1);  //这里没有输出,
render(outMsg);
以上语句没有输出,请问是么原因??



public class WeixinDemoController extends WeixinMsgController {
	
	private static final String helpStr = "\t发送 help 可获得帮助,发送 \"美女\" 可看美女,发送 news 可看新闻,发送 music 可听音乐,你还可以试试发送图片、语音、位置、收藏等信息,看会有什么 。公众号持续更新中,想要更多惊喜欢迎每天关注 ^_^";
	
	/**
	 * 实现父类抽方法,处理文本消息
	 * 本例子中根据消息中的不同文本内容分别做出了不同的响应,同时也是为了测试 jfinal weixin sdk的基本功能:
	 *     本方法仅测试了 OutTextMsg、OutNewsMsg、OutMusicMsg 三种类型的OutMsg,
	 *     其它类型的消息会在随后的方法中进行测试
	 */
	protected void processInTextMsg(InTextMsg inTextMsg) {
		String msgContent = inTextMsg.getContent().trim();
		// 帮助提示
		System.out.println("----------processInTextMsg------------------");
		System.out.println("server  received char is :"+msgContent);
		
	
		if ("help".equalsIgnoreCase(msgContent)) {
			System.out.println("begin to process the msg ----- ");  //这里能输出
			OutTextMsg outMsg = new OutTextMsg(inTextMsg);
			outMsg.setContent(helpStr);
			
			String outMsgXml1 = OutMsgXmlBuilder.build(outMsg);
			System.out.println(outMsgXml1);  //这里没有输出,
			
			render(outMsg);
		}
		// 图文消息测试
		else if ("news".equalsIgnoreCase(msgContent)) {
			OutNewsMsg outMsg = new OutNewsMsg(inTextMsg);
			outMsg.addNews("JFinal 1.8 发布,JAVA 极速 WEB+ORM 框架", "现在就加入 JFinal 极速开发世界,节省更多时间去跟女友游山玩水 ^_^", "http://mmbiz.qpic.cn/mmbiz/zz3Q6WSrzq1ibBkhSA1BibMuMxLuHIvUfiaGsK7CC4kIzeh178IYSHbYQ5eg9tVxgEcbegAu22Qhwgl5IhZFWWXUw/0", "http://mp.weixin.qq.com/s?__biz=MjM5ODAwOTU3Mg==&mid=200313981&idx=1&sn=3bc5547ba4beae12a3e8762ababc8175#rd");
			outMsg.addNews("JFinal 1.6 发布,JAVA极速WEB+ORM框架", "JFinal 1.6 主要升级了 ActiveRecord 插件,本次升级全面支持多数源、多方言、多缓", "http://mmbiz.qpic.cn/mmbiz/zz3Q6WSrzq0fcR8VmNCgugHXv7gVlxI6w95RBlKLdKUTjhOZIHGSWsGvjvHqnBnjIWHsicfcXmXlwOWE6sb39kA/0", "http://mp.weixin.qq.com/s?__biz=MjM5ODAwOTU3Mg==&mid=200121522&idx=1&sn=ee24f352e299b2859673b26ffa4a81f6#rd");
			render(outMsg);
		}
		// 音乐消息测试
		else if ("music".equalsIgnoreCase(msgContent)) {
			OutMusicMsg outMsg = new OutMusicMsg(inTextMsg);
			outMsg.setTitle("Listen To Your Heart");
			outMsg.setDescription("建议在 WIFI 环境下流畅欣赏此音乐");
			outMsg.setMusicUrl("http://www.jfinal.com/Listen_To_Your_Heart.mp3");
			outMsg.setHqMusicUrl("http://www.jfinal.com/Listen_To_Your_Heart.mp3");
			outMsg.setFuncFlag(true);
			render(outMsg);
		}
		else if ("美女".equalsIgnoreCase(msgContent)) {
			OutNewsMsg outMsg = new OutNewsMsg(inTextMsg);
			outMsg.addNews("秀色可餐", "JFinal Weixin 极速开发就是这么爽,有木有 ^_^"
							, "http://mmbiz.qpic.cn/mmbiz/zz3Q6WSrzq2GJLC60ECD7rE7n1cvKWRNFvOyib4KGdic3N5APUWf4ia3LLPxJrtyIYRx93aPNkDtib3ADvdaBXmZJg/0"
							,"http://mp.weixin.qq.com/s?__biz=MjM5ODAwOTU3Mg==&mid=200987822&idx=1&sn=7eb2918275fb0fa7b520768854fb7b80#rd");
			render(outMsg);
		}
		// 其它文本消息直接返回原值 + 帮助提示
		else {
			OutTextMsg outMsg = new OutTextMsg(inTextMsg);
			outMsg.setContent("\t文本消息已成功接收,内容为: " + inTextMsg.getContent() + "\n\n" + helpStr);
			render(outMsg);
		}
		
	}




加载中
0
andying
andying
终于搞定,原来是少了freemarker.jar包文件。
0
JFinal
JFinal
   先在本地测试好,没问题后再部署上去,本机测试方法见这里:http://git.oschina.net/jfinal/jfinal-weixin/wikis/JFinal-weixin-demo%E5%92%8C%E8%B0%83%E8%AF%95
0
andying
andying

引用来自“JFinal”的评论

   先在本地测试好,没问题后再部署上去,本机测试方法见这里:http://git.oschina.net/jfinal/jfinal-weixin/wikis/JFinal-weixin-demo%E5%92%8C%E8%B0%83%E8%AF%95

用QQ浏览器,服务器端调试启动不了,我没有使用代理呀:

服务启动失败, 请检查网络设置,参考常见故障原因

请问是什么原因?

0
andying
andying

用ngrok搭建本地调试完成,微信终端发任何字符都出错,

调出报错如下:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at com.jfinal.aop.Invocation.invoke(Invocation.java:87)
	at com.jfinal.weixin.sdk.jfinal.MsgInterceptor.intercept(MsgInterceptor.java:46)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74)
	at com.demo.common.MyContextPathHandler.handle(MyContextPathHandler.java:37)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
	at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
	at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1774)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
	... 17 more
Caused by: java.lang.NoClassDefFoundError: freemarker/core/InvalidReferenceException
	at com.jfinal.weixin.sdk.jfinal.MsgController.render(MsgController.java:112)
	at com.weixin.demo.WeixinDemoController.processInTextMsg(WeixinDemoController.java:61)
	at com.jfinal.weixin.sdk.jfinal.MsgController.index(MsgController.java:67)
	... 22 more
Caused by: java.lang.ClassNotFoundException: freemarker.core.InvalidReferenceException
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	... 25 more



返回顶部
顶部