我的快游戏基于cocos creator 2.0.7。
首先我的游戏是单机游戏,没有服务器的支持。所以只能把签名算法写在本地,首先写好自己的订单信息,然后必须参与签名的字段先构造源串。在orderInfo参数中,在你的订单信息中必填的字段中选择参与签名的信息,提取出来,使用它们构造源串。例如字段url参与订单信息非必填,但是参与签名。只要你的订单信息中没有出现url,签名就可以不包含字段url。
第一步提取出的参数先构造源串。使用一个ksort算法,根据键值的ASCII码增序排序。我是在网上百度搜到的方法,拷过来单独写一个类,模块化。用到的时候调用就可以。
var SignScript ={
ksort(inputArr, sort_flags) {
// discuss at: http://phpjs.org/functions/ksort/
// original by: GeekFG (http://geekfg.blogspot.com)
// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// improved by: Brett Zamir (http://brett-zamir.me)
// note: The examples are correct, this is a new way
// note: This function deviates from PHP in returning a copy of the array instead
// note: of acting by reference and returning true; this was necessa