Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPhone功能不可用 #5

Open
AnotherW opened this issue Apr 3, 2018 · 1 comment
Open

getPhone功能不可用 #5

AnotherW opened this issue Apr 3, 2018 · 1 comment

Comments

@AnotherW
Copy link

AnotherW commented Apr 3, 2018

貌似是因为没有实现 调用的云函数,可以分享一下demo里用到的云函数吗?

@magic007
Copy link
Owner

magic007 commented Apr 3, 2018

可以的,你在创建的时候,那里有很多模板,其中一个就是这个代码。

function onRequest(request, response, modules) {

var appId = 'wx094ede192e7e64b5'
var sessionKey = request.body.sessionKey || 'QQiAgWqKv4hu4Lkn6XE0Jw=='
var encryptedData = request.body.encryptedData || 'FyTPbuir1sSNPvaPxxZiUKatMUuuSi16OlkM7mB+U3pxvdCJ7zUrTz9dnZGnSmi8grDYw/g3GU9bCNUrRGQZ2BORLGKXhCEFBme4n0XJAL/uXwIeivFsZIBkaEfFrAh/DvJGibeCDkfO2zHcSOKTsDwtEBbGdJUz/N3o2WG33m27V72t30UUe+CE26rucjM1zJqHkHEsSr9YOZlFodE0+Q=='
var iv = request.body.iv || '74ExWKy/mxV22YeWaJOVVw=='

var groupid = groupIdParse(modules, sessionKey, encryptedData, iv)
var jsongid = JSON.parse(groupid);
response.end(groupid);
return;

function groupIdParse(modules, sessionKey, encryptedData, iv) {
    var crypto = modules.oCrypto;
    var sessionKey = new Buffer(sessionKey, 'base64'); //new Base64().decode(sessionKey);
    encryptedData = new Buffer(encryptedData, 'base64'); //new Base64().decode(encryptedData);
    iv = new Buffer(iv, 'base64'); //new Base64().decode(iv)
    var result = '';
    try {
        // 解密
        var decipher = crypto.createDecipheriv('aes-128-cbc', sessionKey, iv)
        // 设置自动 padding 为 true,删除填充补位
        decipher.setAutoPadding(true)
        var decoded = decipher.update(encryptedData, 'binary', 'utf8')
        decoded += decipher.final('utf8')
        result = decoded;
        // decoded = JSON.parse(decoded)
    } catch (err) {
        throw new Error('Illegal Buffer123' + err)
    }
   
    return result;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants