微信公众平台“发生未知错误”的解决方法之一

最近想玩微信公众平台开发。
在填写服务器配置的时候,点击提交总也不通过,显示“发生未知错误,请重试”(大意如此);
搜了半天也没得到什么有用的东西,有很多答案居然是换个浏览器就可以了。然而我从Chrome到Firefox到Edge甚至IE都换过了,依然没有解决。

随后读了一下文档,猜想,该不是在提交配置的时候微信公众平台就要测试吧?
就快速写了一个客户端。按照文档方法加密验证签名。果然提交成功。

关键点在下面:

开发者提交信息后,微信服务器将发送GET请求到填写的服务器地址URL上,GET请求携带参数如下表所示:

参数
描述
signature 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。
timestamp 时间戳
nonce 随机数
echostr 随机字符串

开发者通过检验signature对请求进行校验(下面有校验方式)。若确认此次GET请求来自微信服务器,请原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败。加密/校验流程如下:

1)将token、timestamp、nonce三个参数进行字典序排序

2)将三个参数字符串拼接成一个字符串进行sha1加密

3)开发者获得加密后的字符串可与signature对比,标识该请求来源于微信

简单来说就是验证一下服务器。在提交服务器设置的时候你可以不用管这个验证过程,直接返回echostr即可。等配置提交完成了再实现也没问题。

 

所以微信你可否给一些更友好一点的错误提示呢?诸如“未能连接到你的服务器”?

WebExtension: Block request after response header received in Firefox and Chrome Extension

Well. Firefox finally admitted that Chrome’s extension system is better than it’s XUL or Add-on SDK.

So from Firefox 45+, it started to support WebExtension. And now, it even does not allow any extension that is not built with WebExtension API.

This is a good news, because if you want your extension run on both Chrome and Firefox. you won’t need to build twice.

However, even Firefox is trying to support all of the WebExtension API. There are still some differences between Chrome and Firefox.

Recently I got this one.

I was trying to block some requests with the WebRequest API after response header just received. In Chrome, you can easily do it with an onHeadersReceived listener. like this:

 chrome.webRequest.onHeadersReceived.addListener(
    function (details) {
        let block = THE CONDITIONS THAT YOU WANT TO USE;
        return {cancel: block};

    },
    {urls: ["URL PATTERN"], types: ["TYPES"]},
    ["blocking"]); 

But in Firefox, this is not gonna work. Because in Firefox, you can not block a request after the response headers received, you can only redirect it. So you need to to this:

 chrome.webRequest.onHeadersReceived.addListener(
    function (details) {
        let block = THE CONDITIONS THAT YOU WANT TO USE;
        return {cancel: block, redirectUrl: "://127.0.0.1"};

    },
    {urls: ["URL PATTERN"], types: ["TYPES"]},
    ["blocking"]); 

with the redirectUrl: “://127.0.0.1”, you will redirect it to a local address, and means block it.

How to fix “[Error] ScriptError: Document DocumetID is missing (perhaps it was deleted?)” in Google Script

I’ve created a Google Script APP to help someone export Gmail data to Google SpreadSheet.

It works well when I was testing. But after I publish it as web app, and other users got an error which says

[Error] ScriptError: Document DOCUMENT_ID is missing (perhaps it was deleted?).

And no authorize permission form popups up.  I did not get any useful answer in Google.

After several tests I found I made a stupid mistake.

When publishing the Google Script as web app or other types of APP. There are several options need to take carefully.

Execute the app as:

should set as “User accessing the web app“. (The default value is  Me(myself email)).

With this option, when user first use your app, the authorize permission form will popup and ask user to allow your app access their Google APP.

And no more Document is missing error.

Also don’t forget to chose Anyone in the Who has access to the app option.

 

 

 

How to debug Chrome extension Native Messaging app

 

Here is how to debug native messageing: enable logging.

By adding a flag, it can open Chrome logging window when starting Chrome.

For Windows, you just need to right click on the Chrome icon in your installation folder / shortcut / taskbar —— Properties  —— add this line behind the target string:

[code]–enable-logging –v=1[/code]

A logging window will start with the Chrome. There the native messaging stuff will be print out.

迄今为止最便捷的免费SSL证书服务:腾讯云

现在都用SSL了。 这段时间一直在折腾启用这个网站的SSL,前后试过Let’s encrypt 和StartSSL两个服务,均出现各种问题,配置过程也比较繁琐。耗费掉数十个小时不说,也有些备受打击。

而且StartSSL据称被著名流氓公司奇虎360收购了。对于Let’s encrypt,Chrome和iOS似乎对个人签署的证书也不友好,经常显示不信任。

辗转搜索,有人推荐用腾讯云提供的免费个人证书服务,试用下来步骤非常简单,配置也相当傻瓜化,几分钟即可完成。

这里粗略记录一下。

腾讯云SSL服务地址是:https://console.qcloud.com/ssl

若你还未注册,则需要用QQ或者微信登录,然后通过手机号进行简单的注册。

要申请证书,还需要使用真实姓名和身份证号进行实名认证。填入后若正确可即时通过认证,无需上传照片。

然后点击申请证书, 选择左侧的免费证书即可(也可在右侧购买收费证书) Read More

This Site Enabled SSL

Today I finally got some time to work on my own site.

This small blog used to on a small VPS.

I moved it to Vultr because I heard it is a powerful VPS and it’s price is fair too.

I also enabled SSL, using Free SSL certificate supplier Tencent Cloud service. It’s good, easy to config and doesn’t need to verify again in 1 years.

Got A+ 🙂

iPhone 6S 自动关机问题可能比苹果想象的要严重

在中消协发出查询函以后,苹果对iPhone 6S 近期大量出现的自动关机问题给出的回复是, 电池相关的某个部件在组装前由于长时间暴露在受控环境空气中的时间过长。导致装有这批电池的6S会出现在较寒冷温度下自动关机的问题。

苹果定义的是“一小批”在2015年9月和10月出产的手机会有这样的问题, 并提供了查询网页让消费者查询自己的手机是否在这“一小批”中。符合此条件的手机将可以免费更换电池,若此前已经付费更换电池的用户,则可以报销费用。

我本人的6S也不幸中招,然而并非苹果说的较寒冷的温度下。根据我的使用记录,在室温14度左右下,依然出现电量高达40%以上的时候关机,室温6度左右的时候,出现电量迅速消耗的情况,大约每一分钟掉2%左右的电量,而我仅仅是在浏览文字网页。

而根据我加的几个相关QQ群内的反应,很多并非2015年9月、10月生产的iPhone也有相应的问题,型号从5到6 PLUS都有。而在其他社交媒体上抱怨自己手机这一问题的也很多,遍布全球。因此有理由相信,这并非苹果说的一小批。

其实去年我的一部5C也出现一样的情况,好在当时在保,苹果给换机了事。可惜后来不就这部5C就丢了。

虽然之前给出了免费更换电池的解决措施,然而很多用户反应,即使在更换新电池以后,依然会出现自动关机现象,有些人在更换电池以后这一问题虽然得以缓解,但并未完全解决。不少用户猜测问题可能出在主板上。出于此原因,我一直未去更换自己电池。

苹果说本周推出的iOS10系统更新将包含可以更有效诊断这一问题的内容,期待苹果能给出一个满意的解答。

 

KickAssTorrent is down… for a stupid mistake

The world’s biggest torrent sharing website KickAssTorrent was shutdown at 22/7/2016.

This is what happens:

  • An undercover agent of FBI contacted the owner of kickass for advertisement, got his email ID
  • The Owner then purchased something with same email ID in Apple’s store
  • Got exposed. The police arrested him in Poland
  • KickAssTorrent website was shutdown

He hided so many years for running this website, how comes he use the same email to purchase in Apple store and contact with others?

So stupid.