cloudid.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // miniprogram/pages/openapi/cloudid/cloudid.js
  2. Page({
  3. data: {
  4. weRunResult: '',
  5. userInfoResult: '',
  6. },
  7. onGetWeRunData() {
  8. wx.getWeRunData({
  9. success: res => {
  10. wx.cloud.callFunction({
  11. name: 'echo',
  12. data: {
  13. // info 字段在云函数 event 对象中会被自动替换为相应的敏感数据
  14. info: wx.cloud.CloudID(res.cloudID),
  15. },
  16. }).then(res => {
  17. console.log('[onGetWeRunData] 收到 echo 回包:', res)
  18. this.setData({
  19. weRunResult: JSON.stringify(res.result),
  20. })
  21. wx.showToast({
  22. title: '敏感数据获取成功',
  23. })
  24. }).catch(err => {
  25. console.log('[onGetWeRunData] 失败:', err)
  26. })
  27. }
  28. })
  29. },
  30. onGetUserInfo(e) {
  31. console.log(e)
  32. wx.cloud.callFunction({
  33. name: 'openapi',
  34. data: {
  35. action: 'getOpenData',
  36. openData: {
  37. list: [
  38. e.detail.cloudID,
  39. ]
  40. }
  41. }
  42. }).then(res => {
  43. console.log('[onGetUserInfo] 调用成功:', res)
  44. this.setData({
  45. userInfoResult: JSON.stringify(res.result),
  46. })
  47. wx.showToast({
  48. title: '敏感数据获取成功',
  49. })
  50. })
  51. }
  52. })