收藏
回答

云函数获取stable_token提示41002没有appid?

云函数代码
// 云函数入口文件
const cloud = require('wx-server-sdk')
const request = require('request') 
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境 
const db = cloud.database()
const _ = db.command 


// 云函数入口函数
exports.main = async (event, context) => {
  let token=await get_token()
  return token 
}

async function get_token(){
 const APPIDx ="wxxxxxxxx"
 const APPSECRETx ="8cxxxxxx" //密钥 
 const URL = 'https://api.weixin.qq.com/cgi-bin/stable_token?grant_type=client_credential&appid='+APPIDx+'&secret='+APPSECRETx
  
 const rp= options=> 
   new Promise(resolve,reject)=>{
    request(options,(error,response,body)=>{
      if(error){
       reject(error) 
      }
      resolve(response)
    })
   })
 const result= await rp({
   url:URL,
   method:'POST', 
 }) 
 return (typeof result.body === 'object')? result.body : JSON.parse(result.body)

}

总是返回 errcode: 41002, errmsg: "appid missing rid: 64cdca30-125b1172-28e56d27"
但是url里边已经传了
账号密码都没问题,小程序端调用可以成功拿到token,但是云函数端就不行
回答关注问题邀请回答
收藏

1 个回答

  • showms
    showms
    2023-08-05

    多看文档,appid/secret不是拼接在url后面

    2023-08-05
    有用 1
    回复 5
    • 蓝色禁药 
      蓝色禁药 
      2023-08-07
      我去神奇
      2023-08-07
      回复
    • 蓝色禁药 
      蓝色禁药 
      2023-08-07
      必须关注一波
      2023-08-07
      回复
    • 红莲
      红莲
      2023-10-11
      我这还是不行啊
      2023-10-11
      回复
    • showms
      showms
      2023-10-11回复红莲
      不是放在form里面,post是放在body里面
      2023-10-11
      回复
    • 红莲
      红莲
      2023-10-11
      好了,谢谢
      2023-10-11
      回复
登录 后发表内容