此方法已失效,最新方法请访问本人的这篇文章:巧用七牛https域名,无需反代让多说支持SSL和CDN加速

上次说到多说头像导致https是小黄锁的问题,今天谷歌了下就解决了~ ~ _(:з」∠)__

感谢shiniv的博文,这里基于这篇博文做了些许修改与更新,大致整理如下:

首先,找到wp-content/plugins/duoshuo/里的WordPress.php,找到里面引用的embed.js的路径,把它下载下来,然后,找到下面的代码:

1
2
3
avatarUrl: function(e, t) {
return e.avatar_url || nt.data.default_avatar_url
}

替换成这样:

1
2
3
4
5
6
7
8
9
10
avatarUrl: function (e, t) {
if (e.avatar_url) {
e.avatar_url = (document.location.protocol == "https:") ? e.avatar_url.replace(/http:/, "https:") : e.avatar_url;
e.avatar_url = (document.location.protocol == "https:") ? e.avatar_url.replace(/ds\.cdncache\.org/, "ds.duoshuo.com") : e.avatar_url
} else {
nt.data.default_avatar_url = (document.location.protocol == "https:") ? nt.data.default_avatar_url.replace(/http:/, "https:") : nt.data.default_avatar_url;
nt.data.default_avatar_url = (document.location.protocol == "https:") ? nt.data.default_avatar_url.replace(/ds\.cdncache\.org/, "ds.duoshuo.com") : nt.data.default_avatar_url;
}
return e.avatar_url || nt.data.default_avatar_url
}

上面的代码主要是对多说请求的头像图片链接将http转换为https,多说的ds.cdncache.org默认是http的,而https会被跳转到ds.duoshuo.com,而导致证书和请求链接不符,默认被浏览器拦截!
不过,ds.duoshuo.com是支持https但是在http下会返回502的,于是我们判断下请求头是https就把ds.cdncache.org替换成ds.duoshuo.com.
再加上sinaimg-cdn已经支持https了,所以目前已经可以对多说的所有头像都做https的替换.

当然如果不想格式化再压缩的话,也可以把上面的代码直接去掉换行符在替换,如下:

1
if(e.avatar_url) {e.avatar_url = (document.location.protocol == "https:") ? e.avatar_url.replace(/http:/, "https:") : e.avatar_url;e.avatar_url = (document.location.protocol == "https:") ? e.avatar_url.replace(/ds\.cdncache\.org/, "ds.duoshuo.com"): e.avatar_url} else {nt.data.default_avatar_url = (document.location.protocol == "https:") ? nt.data.default_avatar_url.replace(/http:/, "https:") : nt.data.default_avatar_url;nt.data.default_avatar_url = (document.location.protocol == "https:") ? nt.data.default_avatar_url.replace(/ds\.cdncache\.org/, "ds.duoshuo.com") : nt.data.default_avatar_url;}

直接插入在avatarUrl: function(e, t) {和return e.avatar_url || nt.data.default_avatar_url}之间就可以了.

这里提供了本人的embed.js文件供参考:

然后把它保存,上传到七牛上面,再将duoshuo文件夹下的WordPress.php中embed.js的路径改为七牛的外链地址即可.

或者也可以参考本人的这篇文章,自行匹配在http和https下给多说调用不同的js文件.

这下总算可以全站看到小绿锁了,哈哈~ ~

duoshuo_ssl_success

当然,还有个问题就是如果发了表情和图片的话,仍然是小黄锁的,因为新浪的表情走https的话会报证书错误…@_@

偷点懒,在后台多说的个性化设置里把”允许插入表情”关掉就是了.

参考链接:

更换多说评论插件的头像地址