添加分享到朋友圈发送给好友分享等按钮

微信内嵌浏览器

通过 Mac 远程调试 iPhone 上微信自己的网页,我们可以发现微信内嵌浏览器定义了一个私有 JavaScript 对象:WeixinJSBridge,通过操作这个对象的相关方法可以实现分享到微信朋友圈,和判断一个微信号的关注状态以及实现关注指定微信号等功能。

分享到朋友圈


  1. function weixinShareTimeline(title,desc,link,imgUrl){
  2. WeixinJSBridge.invoke('shareTimeline',{
    
  3.     "img_url":imgUrl,
    
  4.     //"img_width":"640",
    
  5.     //"img_height":"640",
    
  6.     "link":link,
    
  7.     "desc": desc,
    
  8.     "title":title
    
  9. });
    
  10. }

发送给好友


  1. function weixinSendAppMessage(title,desc,link,imgUrl){
  2. WeixinJSBridge.invoke('sendAppMessage',{
    
  3. //"appid":appId,
    
  4. "img_url":imgUrl,
    
  5. //"img_width":"640",
    
  6. //"img_height":"640",
    
  7. "link":link,
    
  8. "desc":desc,
    
  9. "title":title
    
  10. });
    
  11. }

分享到腾讯微博


  1. function weixinShareWeibo(title,link){
  2. WeixinJSBridge.invoke('shareWeibo',{
    
  3.     "content":title + link,
    
  4.     "url":link
    
  5. });
    
  6. }

关注指定的微信号


  1. function weixinAddContact(name){
  2. WeixinJSBridge.invoke("addContact", {webtype: "1",username: name}, **function**(e) {
    
  3.     WeixinJSBridge.log(e.err_msg);
    
  4.     //e.err_msg:add_contact:added 已经添加
    
  5.     //e.err_msg:add_contact:cancel 取消添加
    
  6.     //e.err_msg:add_contact:ok 添加成功
    
  7.     **if**(e.err_msg == 'add_contact:added' || e.err_msg == 'add_contact:ok'){
    
  8.         //关注成功,或者已经关注过
    
  9.     }
    
  10. })
    
  11. }

如果您觉得上面的内容对您有帮助,可以打赏支持一下!

打赏

关键词:javascript

网友留言(0 条)

发表评论

验证码