第一,我服务器端使用的是php;
第二,;
第三,
当我在开放数据域下执行:
function testInteractive() {
let toOpenid = "oYfkb5CGHzSlS7pMCjNgIb2L6_3I";
toOpenid = "oYfkb5EIzrH8asXxdRmY0no8TbyE";
wx.modifyFriendInteractiveStorage({
key: '1',
opNum: 1,
operation: 'add',
toUser: toOpenid,
success: (res) => {
console.log("发送成功!" + JSON.stringify(res));
},
fail: (err) => {
console.log('err', err)
}
})
}
只返回了这个结果:{"errMsg":"modifyFriendInteractiveStorage:ok"};
第四,checkInteractiveData.js里面没有任何反应,checkInteractiveData.js是在微信的服务器端执行么?
第五,checkInteractiveData.js中的代码:
exports.main = function (arg) {
try {
arg = JSON.parse(arg)
const myOpenid = wx.getOpenId()
const toOpenid = arg.toUser
const opNum = arg.opNum
const now = new Date()
const giftStorageKey = now.toDateString()
const friendsStorage = wx.getFriendUserStorage([giftStorageKey])
const userList = friendsStorage.user_item
let ok = false
// 用户每天只能给同一个好友赠送一次金币,每天最多送5次
const friendData = userList.find(userItem => userItem.openid === toOpenid)
const myData = userList.find(userItem => userItem.openid === myOpenid)
if (friendData) {
const friendKV = friendData.kv_list[friendData.kv_list.length - 1]
const selfKV = myData.kv_list[myData.kv_list.length - 1]
let friendGift = friendKV && friendKV.value
let selfGift = selfKV && selfKV.value
if (friendGift) {
friendGift = JSON.parse(friendGift)
} else {
friendGift = {
receiveRecords: [],
sendCount: 0
}
}
if (selfGift) {
selfGift = JSON.parse(selfGift)
} else {
selfGift = {
receiveRecords: [],
sendCount: 0
}
}
// 金币重复送给同一个人
const giftToSameOne = friendGift && friendGift.receiveRecords.some(item => {
return item.fromOpenid === myOpenid
})
// 赠送次数超过限制
const outLimit = selfGift && selfGift.sendCount >= 1
const canNotGift = giftToSameOne || outLimit
// 验证
if (!canNotGift) {
friendGift.receiveRecords.push({
fromOpenid: myOpenid,
time: Date.now()
})
selfGift.sendCount = selfGift.sendCount + 1
// 写对方的数据
let ret1 = wx.setFriendUserStorage(toOpenid, [{
key: giftStorageKey,
value: JSON.stringify(friendGift)
}])
// 写自己的数据
let ret2 = wx.setFriendUserStorage(myOpenid, [{
key: giftStorageKey,
value: JSON.stringify(selfGift)
}])
if (ret1.errcode == 0 && ret2.errcode == 0) {
ok = true
} else {
console.error('fail')
}
}
}
if (ok) {
// 验证通过
return JSON.stringify({ "ret": true });
} else {
// 验证不通过
return 'validate fail';
}
} catch (err) {
console.error(err.message)
}
}
第六:请问我哪做错了?
只返回了这个结果:{"errMsg":"modifyFriendInteractiveStorage:ok"};
说明数据修改成功了,这个接口成功没有其他参数返回。