1***@qq.com
1***@qq.com
  • 发布:2023-06-09 22:19
  • 更新:2023-06-12 11:47
  • 阅读:190

weixin-server里的uniCloud.getCloudInfos()为空

分类:uniCloud

weixin-server里的uniCloud.getCloudInfos()为空
获取应用级token 然后到```javascript
function isAliyun() {
console.warn('isAliyun',uniCloud.getCloudInfos())
return (uniCloud.getCloudInfos()[0].provider === 'aliyun')
}

这里的uniCloud.getCloudInfos()为空  
打印uniCloud显示如下
```javascript  
{  
    "$provider": "aliyun",  
    "$options": {  
        "context": {  
            "CLIENTIP": "127.0.0.1",  
            "CLIENTUA": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 HBuilderX",  
            "FUNCTION_NAME": "yule-weixin",  
            "SPACEINFO": {  
                "provider": "aliyun",  
                "spaceId": "999999999999999999999",  
                "useOldSpaceId": false  
            },  
            "SOURCE": "client",  
            "requestId": "29438791-5dec-4743-856a-ba892b86298c",  
            "mpserverless": {  
                "options": {  
                    "endpoint": "https://api.next.bspapp.com",  
                    "logger": {  
                        "log": function() {  
                            [native code]  
                        },  
                        "warn": function() {  
                            [native code]  
                        },  
                        "dir": function() {  
                            [native code]  
                        },  
                        "time": function() {  
                            [native code]  
                        },  
                        "timeEnd": function() {  
                            [native code]  
                        },  
                        "timeLog": function() {  
                            [native code]  
                        },  
                        "trace": function() {  
                            [native code]  
                        },  
                        "assert": function() {  
                            [native code]  
                        },  
                        "clear": function() {  
                            [native code]  
                        },  
                        "count": function() {  
                            [native code]  
                        },  
                        "countReset": function() {  
                            [native code]  
                        },  
                        "group": function() {  
                            [native code]  
                        },  
                        "groupEnd": function() {  
                            [native code]  
                        },  
                        "table": function() {  
                            [native code]  
                        },  
                        "debug": function() {  
                            [native code]  
                        },  
                        "info": function() {  
                            [native code]  
                        },  
                        "dirxml": function() {  
                            [native code]  
                        },  
                        "error": function() {  
                            [native code]  
                        },  
                        "groupCollapsed": function() {  
                            [native code]  
                        },  
                        "Console": function Console(options /* or: stdout, stderr, ignoreErrors = true */ ) {  
                            // We have to test new.target here to see if this function is called  
                            // with new, because we need to define a custom instanceof to accommodate  
                            // the global console.  
                            if (new.target === undefined) {  
                                return ReflectConstruct(Console, arguments);  
                            }  

                            if (!options || typeof options.write === 'function') {  
                                options = {  
                                    stdout: options,  
                                    stderr: arguments[1],  
                                    ignoreErrors: arguments[2]  
                                };  
                            }  

                            const {  
                                stdout,  
                                stderr = stdout,  
                                ignoreErrors = true,  
                                colorMode = 'auto',  
                                inspectOptions,  
                                groupIndentation,  
                            } = options;  

                            if (!stdout || typeof stdout.write !== 'function') {  
                                throw new ERR_CONSOLE_WRITABLE_STREAM('stdout');  
                            }  
                            if (!stderr || typeof stderr.write !== 'function') {  
                                throw new ERR_CONSOLE_WRITABLE_STREAM('stderr');  
                            }  

                            if (typeof colorMode !== 'boolean' && colorMode !== 'auto')  
                                throw new ERR_INVALID_ARG_VALUE('colorMode', colorMode);  

                            if (groupIndentation !== undefined) {  
                                validateInteger(groupIndentation, 'groupIndentation',  
                                    0, kMaxGroupIndentation);  
                            }  

                            if (inspectOptions !== undefined) {  
                                validateObject(inspectOptions, 'options.inspectOptions');  

                                if (inspectOptions.colors !== undefined &&  
                                    options.colorMode !== undefined) {  
                                    throw new ERR_INCOMPATIBLE_OPTION_PAIR(  
                                        'options.inspectOptions.color', 'colorMode');  
                                }  
                                optionsMap.set(this, inspectOptions);  
                            }  

                            // Bind the prototype functions to this Console instance  
                            ArrayPrototypeForEach(ObjectKeys(Console.prototype), (key) => {  
                                // We have to bind the methods grabbed from the instance instead of from  
                                // the prototype so that users extending the Console can override them  
                                // from the prototype chain of the subclass.  
                                this[key] = FunctionPrototypeBind(this[key], this);  
                                ObjectDefineProperty(this[key], 'name', {  
                                    __proto__: null,  
                                    value: key  
                                });  
                            });  

                            this[kBindStreamsEager](stdout, stderr);  
                            this[kBindProperties](ignoreErrors, colorMode, groupIndentation);  
                        },  
                        "profile": function profile() {  
                            [native code]  
                        },  
                        "profileEnd": function profileEnd() {  
                            [native code]  
                        },  
                        "timeStamp": function timeStamp() {  
                            [native code]  
                        },  
                        "context": function context() {  
                            [native code]  
                        }  
                    },  
                    "timeout": 60000,  
                    "spaceId": "88888888888888888888888888",  
                    "serverSecret": "-----BEGIN PRIVATE KEY----------END PRIVATE KEY-----",  
                    "clientSecret": "e8KcgfD5kD/yKYqKVbRQjw=="  
                },  
                "_debug": false,  
                "_logger": {  
                    "log": function() {  
                        [native code]  
                    },  
                    "warn": function() {  
                        [native code]  
                    },  
                    "dir": function() {  
                        [native code]  
                    },  
                    "time": function() {  
                        [native code]  
                    },  
                    "timeEnd": function() {  
                        [native code]  
                    },  
                    "timeLog": function() {  
                        [native code]  
                    },  
                    "trace": function() {  
                        [native code]  
                    },  
                    "assert": function() {  
                        [native code]  
                    },  
                    "clear": function() {  
                        [native code]  
                    },  
                    "count": function() {  
                        [native code]  
                    },  
                    "countReset": function() {  
                        [native code]  
                    },  
                    "group": function() {  
                        [native code]  
                    },  
                    "groupEnd": function() {  
                        [native code]  
                    },  
                    "table": function() {  
                        [native code]  
                    },  
                    "debug": function() {  
                        [native code]  
                    },  
                    "info": function() {  
                        [native code]  
                    },  
                    "dirxml": function() {  
                        [native code]  
                    },  
                    "error": function() {  
                        [native code]  
                    },  
                    "groupCollapsed": function() {  
                        [native code]  
                    },  
                    "Console": function Console(options /* or: stdout, stderr, ignoreErrors = true */ ) {  
                        // We have to test new.target here to see if this function is called  
                        // with new, because we need to define a custom instanceof to accommodate  
                        // the global console.  
                        if (new.target === undefined) {  
                            return ReflectConstruct(Console, arguments);  
                        }  

                        if (!options || typeof options.write === 'function') {  
                            options = {  
                                stdout: options,  
                                stderr: arguments[1],  
                                ignoreErrors: arguments[2]  
                            };  
                        }  

                        const {  
                            stdout,  
                            stderr = stdout,  
                            ignoreErrors = true,  
                            colorMode = 'auto',  
                            inspectOptions,  
                            groupIndentation,  
                        } = options;  

                        if (!stdout || typeof stdout.write !== 'function') {  
                            throw new ERR_CONSOLE_WRITABLE_STREAM('stdout');  
                        }  
                        if (!stderr || typeof stderr.write !== 'function') {  
                            throw new ERR_CONSOLE_WRITABLE_STREAM('stderr');  
                        }  

                        if (typeof colorMode !== 'boolean' && colorMode !== 'auto')  
                            throw new ERR_INVALID_ARG_VALUE('colorMode', colorMode);  

                        if (groupIndentation !== undefined) {  
                            validateInteger(groupIndentation, 'groupIndentation',  
                                0, kMaxGroupIndentation);  
                        }  

                        if (inspectOptions !== undefined) {  
                            validateObject(inspectOptions, 'options.inspectOptions');  

                            if (inspectOptions.colors !== undefined &&  
                                options.colorMode !== undefined) {  
                                throw new ERR_INCOMPATIBLE_OPTION_PAIR(  
                                    'options.inspectOptions.color', 'colorMode');  
                            }  
                            optionsMap.set(this, inspectOptions);  
                        }  

                        // Bind the prototype functions to this Console instance  
                        ArrayPrototypeForEach(ObjectKeys(Console.prototype), (key) => {  
                            // We have to bind the methods grabbed from the instance instead of from  
                            // the prototype so that users extending the Console can override them  
                            // from the prototype chain of the subclass.  
                            this[key] = FunctionPrototypeBind(this[key], this);  
                            ObjectDefineProperty(this[key], 'name', {  
                                __proto__: null,  
                                value: key  
                            });  
                        });  

                        this[kBindStreamsEager](stdout, stderr);  
                        this[kBindProperties](ignoreErrors, colorMode, groupIndentation);  
                    },  
                    "profile": function profile() {  
                        [native code]  
                    },  
                    "profileEnd": function profileEnd() {  
                        [native code]  
                    },  
                    "timeStamp": function timeStamp() {  
                        [native code]  
                    },  
                    "context": function context() {  
                        [native code]  
                    }  
                },  
                "transport": {  
                    "endpoint": "https://api.next.bspapp.com",  
                    "authType": undefined,  
                    "protocol": "HTTP",  
                    "logger": {  
                        "log": function() {},  
                        "info": function() {},  
                        "warn": function() {},  
                        "error": function() {},  
                        "debug": function() {}  
                    },  
                    "appId": undefined,  
                    "appSecret": "-----BEGIN PRIVATE KEY---------END PRIVATE KEY-----",  
                    "spaceId": "8888",  
                    "timeout": 60000,  
                    "ua": "pkg_name:@alicloud/mpserverless-node-sdk;ver:1.2.3;",  
                    "httpRequest": function request(url, args, callback) {  
                        // request(url, callback)  
                        if (arguments.length === 2 && typeof args === 'function') {  
                            callback = args;  
                            args = null;  
                        }  
                        if (typeof callback === 'function') {  
                            return exports.requestWithCallback(url, args, callback);  
                        }  

                        // Promise  
                        if (!_Promise) {  
                            _Promise = require('any-promise');  
                        }  
                        return new _Promise(function(resolve, reject) {  
                            exports.requestWithCallback(url, args, makeCallback(resolve, reject));  
                        });  
                    }  
                },  
                "pkg": {  
                    "name": "@alicloud/mpserverless-node-sdk",  
                    "author": "junmo <qwe_lingkun@163.com>",  
                    "version": "1.2.3",  
                    "description": "Ant MPServerless JavaScript SDK for FaaS Egg Framework",  
                    "main": "dist/index.js",  
                    "types": "dist/index.d.ts",  
                    "files": ["dist"],  
                    "license": "MIT",  
                    "engines": {  
                        "node": ">=8.0.0"  
                    },  
                    "publishConfig": {  
                        "access": "public"  
                    },  
                    "scripts": {  
                        "tsc": "tsc -p tsconfig.json",  
                        "tsc:w": "npm run tsc -- -w"  
                    },  
                    "dependencies": {  
                        "@alicloud/mp-db-service": "^3.0.0",  
                        "@alicloud/mp-function-service": "^3.0.0",  
                        "@alicloud/mpserverless-node-file-service": "^1.2.0",  
                        "@alicloud/mpserverless-node-user-service": "^1.2.0",  
                        "@alicloud/mpserverless-core": "^3.0.0",  
                        "tslib": "^1.9.3",  
                        "urllib": "^2.34.2"  
                    }  
                },  
                "db": {  
                    "transport": {  
                        "endpoint": "https://api.next.bspapp.com",  
                        "authType": undefined,  
                        "protocol": "HTTP",  
                        "logger": {  
                            "log": function() {},  
                            "info": function() {},  
                            "warn": function() {},  
                            "error": function() {},  
                            "debug": function() {}  
                        },  
                        "appId": undefined,  
                        "appSecret": "-----BEGIN PRIVATE KEY---------END PRIVATE KEY-----",  
                        "spaceId": "888888",  
                        "timeout": 60000,  
                        "ua": "pkg_name:@alicloud/mpserverless-node-sdk;ver:1.2.3;",  
                        "httpRequest": function request(url, args, callback) {  
                            // request(url, callback)  
                            if (arguments.length === 2 && typeof args === 'function') {  
                                callback = args;  
                                args = null;  
                            }  
                            if (typeof callback === 'function') {  
                                return exports.requestWithCallback(url, args, callback);  
                            }  

                            // Promise  
                            if (!_Promise) {  
                                _Promise = require('any-promise');  
                            }  
                            return new _Promise(function(resolve, reject) {  
                                exports.requestWithCallback(url, args, makeCallback(resolve, reject));  
                            });  
                        }  
                    }  
                },  
                "user": {  
                    "transport": {  
                        "endpoint": "https://api.next.bspapp.com",  
                        "authType": undefined,  
                        "protocol": "HTTP",  
                        "logger": {  
                            "log": function() {},  
                            "info": function() {},  
                            "warn": function() {},  
                            "error": function() {},  
                            "debug": function() {}  
                        },  
                        "appId": undefined,  
                        "appSecret": "-----BEGIN PRIVATE KEY----------END PRIVATE KEY-----",  
                        "spaceId": "8888888",  
                        "timeout": 60000,  
                        "ua": "pkg_name:@alicloud/mpserverless-node-sdk;ver:1.2.3;",  
                        "httpRequest": function request(url, args, callback) {  
                            // request(url, callback)  
                            if (arguments.length === 2 && typeof args === 'function') {  
                                callback = args;  
                                args = null;  
                            }  
                            if (typeof callback === 'function') {  
                                return exports.requestWithCallback(url, args, callback);  
                            }  

                            // Promise  
                            if (!_Promise) {  
                                _Promise = require('any-promise');  
                            }  
                            return new _Promise(function(resolve, reject) {  
                                exports.requestWithCallback(url, args, makeCallback(resolve, reject));  
                            });  
                        }  
                    }  
                },  
                "file": {  
                    "transport": {  
                        "endpoint": "https://api.next.bspapp.com",  
                        "authType": undefined,  
                        "protocol": "HTTP",  
                        "logger": {  
                            "log": function() {},  
                            "info": function() {},  
                            "warn": function() {},  
                            "error": function() {},  
                            "debug": function() {}  
                        },  
                        "appId": undefined,  
                        "appSecret": "-----BEGIN PRIVATE KEY---------END PRIVATE KEY-----",  
                        "spaceId": "888888",  
                        "timeout": 60000,  
                        "ua": "pkg_name:@alicloud/mpserverless-node-sdk;ver:1.2.3;",  
                        "httpRequest": function request(url, args, callback) {  
                            // request(url, callback)  
                            if (arguments.length === 2 && typeof args === 'function') {  
                                callback = args;  
                                args = null;  
                            }  
                            if (typeof callback === 'function') {  
                                return exports.requestWithCallback(url, args, callback);  
                            }  

                            // Promise  
                            if (!_Promise) {  
                                _Promise = require('any-promise');  
                            }  
                            return new _Promise(function(resolve, reject) {  
                                exports.requestWithCallback(url, args, makeCallback(resolve, reject));  
                            });  
                        }  
                    },  
                    "request": function request(url, args, callback) {  
                        // request(url, callback)  
                        if (arguments.length === 2 && typeof args === 'function') {  
                            callback = args;  
                            args = null;  
                        }  
                        if (typeof callback === 'function') {  
                            return exports.requestWithCallback(url, args, callback);  
                        }  

                        // Promise  
                        if (!_Promise) {  
                            _Promise = require('any-promise');  
                        }  
                        return new _Promise(function(resolve, reject) {  
                            exports.requestWithCallback(url, args, makeCallback(resolve, reject));  
                        });  
                    }  
                },  
                ......还有很多省略

这是什么情况造成的呀

2023-06-09 22:19 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com (作者)

function isAliyun() {  
    console.warn('isAliyun',uniCloud.$provider)  
    return (uniCloud.$provider === 'aliyun')  
  // return (uniCloud.getCloudInfos()[0].provider === 'aliyun')  
}

改成这样成功拿到token了

DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

详细说下你这是什么使用场景?weixin-server是指什么

  • 1***@qq.com (作者)

    你们那个第三方凭证的东东呀

    2023-06-12 15:43

  • DCloud_uniCloud_WYQ

    回复 1***@qq.com: 你用的HBuilderX版本是多少?遇到错误的时候是连的本地云函数还是云端云函数

    2023-06-12 20:18

要回复问题请先登录注册