如上图所示:
1. 先说关注他人的实现方法吧,这个很简单,调用weixin协议即可 具体代码如下:
1 | < a href = "weixin://profile/gh_xxxxxxxx" >关注他</ a > |
这里gh_xxxxxxxx就是用户的原始ID,注意,必须使用原始ID.
2. 分享到朋友圈:
其实利用微信公众账号发布的HTML页面最终是利用微信内置的web浏览器打开的,同事在这个浏览器里集成了WeixinJSBridge这个JS对象,利用这个JS对象的一些操作接口可以实现微信应用内的功能.如添加好友,发送消息等等功能.
01 | function ShareTofriends(img_url,link,title,desc) { |
03 | if (window.WeixinJSBridge) |
05 | if ( typeof (img_url) == 'undefined' || img_url == "" ) |
07 | var img_url = "http://www.sample.com/test.jpg" ; |
09 | if ( typeof (link) == 'undefined' || link == "" ) |
11 | var img_url = window.location.href; |
13 | if ( typeof (title) == 'undefined' || title == "" ) |
15 | var title = '点开看一下吧!' ; |
17 | if ( typeof (desc) == 'undefined' || desc == "" ) |
19 | var desc = "wendoscoo" ; |
21 | WeixinJSBridge.invoke( 'shareTimeline' ,{ |
33 | WeixinJSBridge.log(res.err_msg); |
39 | alert( "WeixinJSBridge对象不存在!!" ); |
然后同样使用一个a标签实现分享功能,加上onclick时间调用分享的JS函数就可以了
1 | < a href = "javascript:void(0);" onclick = "ShareTOfriend('分享弹出窗的图片URL地址','分享的页面链接','分享弹出窗的标题','分享内容的描述')" >分享到朋友圈 |
好了,搞定!
扩展阅读:
http://blog.wpjam.com/m/weixinjsbridge/