谁能给我一个微信开放数据域的源代码?跪求了

一个全的,完全的开放数据域的源代码,谢谢

class Rank {

constructor() {
// 画板
this.canvas = wx.getSharedCanvas()
this.ctx = this.canvas.getContext(‘2d’)

// 配置:
// 头像宽高,参考坐标

}

init() {
// 资料
this.getUserInfo()
this.getMaxScore()
// 监听
this.listen()
}

listen(){
wx.onMessage(msg => {
///// console.log(msg)
// 用户信息
if(!this.userInfo){this.getUserInfo()}
switch (msg.action) {
case 1: //1 横向排名
this.score = msg.score
this.hRank()
break;
case 2:
this.friendRank()
break;
case 3:
this.groupRank(msg.shareTicket)
break;
case 4: // 下一页
this.nextPage()
break;
case 5: // 上一页
this.prePage()
break;
default:
console.log(未知消息类型:msg.action=${msg.action});
break;
}
})
}

// 横向排名
hRank(){
this.clear()
if(this.maxScore < 0){ // => 再次验证积分
this.getMaxScore(true) // => this.setUserData()
return
}
this.setUserData()
}

// 好友排名
friendRank(){
this.clear()
this.getFriendData()
return
}

// 获取好友数据 OK;
getFriendData(isH){
this.clear()
if(!isH){
this.page = 1
this.myRankDisplay = false
}
wx.getFriendCloudStorage({
keyList: [‘maxScore’],
success: res => {
/////console.log(“wx.getFriendCloudStorage success”, res)

// // just for testing
// res.data.push(res.data[0])
// res.data.push(res.data[0])
// res.data.push(res.data[0])
// res.data.push(res.data[0])
// res.data.push(res.data[0])
// res.data.push(res.data[0])
// res.data.push(res.data[0])
// res.data.push(res.data[0])
// res.data.push(res.data[0])
// res.data.push(res.data[0])

// function deepCopy(obj){
// if(typeof obj != ‘object’){
// return obj;
// }
// var newobj = {};
// for ( var attr in obj) {
// newobj[attr] = deepCopy(obj[attr]);
// }
// return newobj;
// }
// var obj2 = deepCopy(res.data[0]);
// obj2.KVDataList[0].value =“500”
// res.data.push(obj2)
// var obj3 = deepCopy(res.data[0]);
// obj3.KVDataList[0].value =“10”
// res.data.push(obj3)
//
//

		this.dataSort(res.data)
		this.pageTotal = Math.ceil(res.data.length/6)
		if(isH){
			this.hDraw()
			return
		}
		this.vDraw()
	},
	fail: res => {
		console.log("wx.getFriendCloudStorage fail", res);
	},
});

}
// 获取群数据 OK;
groupRank(shareTicket){
this.clear()
this.page = 1
this.myRankDisplay = false
wx.getGroupCloudStorage({
shareTicket: shareTicket,
keyList: [‘maxScore’],
success: res => {
/////console.log(“wx.getGroupCloudStorage success”, res)
this.dataSort(res.data)
this.pageTotal = Math.ceil(res.data.length/6)
this.vDraw()
},
fail: res => {
console.log(“wx.getGroupCloudStorage fail”, res);
},
});
}
hDraw() {
// 数据相关
this.clear()
for (var i=1; i<4; i++) {
var user = this.data[i-1]
if (!user){
break
}
var center = i*200-100
// 写排名
this.ctx.fillStyle = “#ff0000”;
this.ctx.textAlign = “center”;
this.ctx.baseLine = “middle”;
this.ctx.font = “30px Helvetica”;
this.ctx.fillText(i, center, 50);

      // 写名字
      this.ctx.fillStyle = "#000000";
      this.ctx.fillText(user.nickname, center, 210, 180);

      // 写分数
      this.ctx.fillStyle = "#ff00ff";
      this.ctx.fillText(user.KVDataList[0].value, center, 255, 180);
      
      // 画头像
      this.drawAvatar(user.avatarUrl,center-50,70,100)
    }
	// 历史最高积分
	this.ctx.fillStyle = "#ff0000";
	this.ctx.font = "36px Helvetica";
	this.ctx.fillText(this.maxScore, 420, 348,200);

}
vDraw(){
this.clicked = true
for (var i=1; i<7; i++) {
var index = i + 6*(this.page-1)-1
var user = this.data[index]
if (!user){
break
}
var yy = i *90 -45 +15
// 写排名
this.ctx.fillStyle = “#ff0000”;
this.ctx.textAlign = “center”;
this.ctx.baseLine = “middle”;
this.ctx.font = “30px Helvetica”;
this.ctx.fillText(index+1, 30, yy,50);

      // 写名字
      this.ctx.fillStyle = "#073190";
      this.ctx.textAlign = "left";
      this.ctx.fillText(user.nickname, 144, yy, 265);

      // 写分数
      this.ctx.fillStyle = "#ff00ff";
      this.ctx.textAlign = "right";
      this.ctx.font = "30px Helvetica";
      this.ctx.fillText(user.KVDataList[0].value, 558, yy, 139);  //570
      
      // 画头像
      this.drawAvatar(user.avatarUrl,60,  (i-1)*90+8, 74) 	 
  }
  
  // 写排名
  if(!this.myRankDisplay){
      var yy = 690
      this.ctx.fillStyle = "#ff0000";
      this.ctx.textAlign = "center";
      this.ctx.font = "30px Helvetica";
      this.ctx.fillText(this.myRrankNum(), 30, yy,50);
      
      // 写名字
      this.ctx.fillStyle = "#073190";
      this.ctx.textAlign = "left";
      this.ctx.fillText(this.userInfo.nickName, 144, yy, 265);

      // 写分数
      this.ctx.fillStyle = "#ff00ff";
      this.ctx.textAlign = "right";
      this.ctx.font = "30px Helvetica";
      this.ctx.fillText(this.maxScore, 558, yy, 139);  //570
      
      // 画头像
      this.drawAvatar(this.userInfo.avatarUrl,60, yy-50, 74) 	
	  this.myRankDisplay = true
  }
  this.clicked = false

}

// 数据整理
dataSort(data){
data.sort(function(a,b){
var av = a.KVDataList[0].value - 0
var bv = b.KVDataList[0].value - 0
return bv-av
})
this.data = data
}

// 我的排名
myRrankNum(){
// userInfo 没有openId, 所以只能计算头像, 然而头像是否是最新的?;
for(var i=0; i<this.data.length; i++){
if(this.data[i].avatarUrl == this.userInfo.avatarUrl){
return i+1
}
}
return ‘me’
}

// 设置积分 + 获取好友数据
setUserData(){
// 整合数据
var list = []
if (this.score > this.maxScore){
this.maxScore = this.score
var now = ‘’ + new Date().getTime()
var score= ‘’ + this.score
// maxScore
list.push({key: ‘maxScore’, value: score})
list.push({key: ‘maxTime’, value: now})
// rank
list.push({key: ‘rank’, value: ‘{“wxgame”:{“score”:’+score+’,“update_time”: ‘+now+’}}’})
// 存储数据
wx.setUserCloudStorage({
KVDataList: list,
success: res => {
this.getFriendData(true)
},
fail: res => {
console.log(res)
}
})
return
}
this.getFriendData(true)
}

// 画头像
drawAvatar(url,x,y,z){
var img = wx.createImage();
img.src = url;
img.onload = () => {
this.ctx.drawImage(img, x, y, z, z);// i*90+8
}
}

nextPage(){
if(this.clicked || (this.page >= this.pageTotal)){
///// console.log(“nex”)
return
}
if(this.myRankDisplay){
this.ctx.clearRect(0, 0, 570, 550);
}
this.page++
this.vDraw()
}
prePage(){
if(this.clicked || (this.page<2)){
///// console.log(“pre”)
return
}

  if(this.myRankDisplay){
	  this.ctx.clearRect(0, 0, 570, 550);
  } 
  this.page--
  this.vDraw()

}

// 清空画板
clear(){
this.ctx.clearRect(0, 0, 1000, 1000);
}

// 获取用户资料
getUserInfo(){
wx.getUserInfo({
openIdList: [“selfOpenId”],
success: res => {
/////console.log(‘用户资料成功’,res)
this.userInfo = res.data[0]
},
fail: res => {
console.log(‘getUserInfo fail!’, res)
}
})
}
// 获取用户最大积分
getMaxScore(isNext){
wx.getUserCloudStorage({
keyList: [“maxScore”], // 1. 若有无效的key,即未存储之KEY,不会返回到数据中; 所以要判断每个成员的key的具体值; 2.返回的数据以升序英文排序的;// 若无Key, 返回空数组[]
success: (res)=>{
/////console.log(res)
var data = res.KVDataList
if(data && data[0]){
this.maxScore = data[0].value -0
}else{
///// console.log(“this is a bug”)
this.maxScore = 0
}
if(isNext){
this.setUserData()
}
},
fail: (res)=>{
/////console.log(‘error’,res)
this.maxScore = -1
},
})
}
}

var rank = new Rank()
rank.init()