Last active
November 4, 2018 14:37
-
-
Save 1c7/3a0b9182ec1c1a07506354f653c8b4c2 to your computer and use it in GitHub Desktop.
微信内容安全,参考代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 微信小程序,内容安全示例代码 | |
const qiniuUploader = require("../../utils/qiniuUploader.js"); // https://github.com/gpake/qiniu-wxapp-sdk | |
const wittcism = require('../../utils/wittcism.js') // API | |
Page({ | |
data: {}, | |
onShow() {}, | |
change_avatar() { | |
qiniuUploader.upload(filePath, (res) => { | |
var original_qiniu_link = res.qiniu_url | |
var link = 'https://img.wittcism.com/' + res.qiniu_url + '?imageView2/2/w/740/h/1324'; | |
var params = { | |
url: link | |
} | |
wittcism.imgSecCheckByURL(params).then(data => { | |
if (data['errmsg'] == 'ok') { | |
// 图片没问题 | |
wx.hideLoading(); | |
that.update_user_avatar(original_qiniu_link); | |
wx.showToast({ | |
title: '修改头像成功', | |
icon: 'success', | |
}) | |
} else { | |
// 提示图片有问题 | |
wx.hideLoading(); | |
if (data['errmsg'] == 'risky') { | |
wx.showToast({ | |
title: '微信内容安全接口认为您上传的图片含有违法违规内容, 修改头像失败', | |
icon: 'none', | |
}) | |
} else { | |
wx.showToast({ | |
title: data['errmsg'], | |
icon: 'none', | |
}) | |
} | |
} | |
}).catch(e => { | |
console.log(e); | |
wx.showToast({ | |
title: '出错了,请稍后再试', | |
icon: 'none', | |
}) | |
}) | |
}, (error) => { | |
wx.hideLoading(); | |
wx.showToast({ | |
title: '上传头像文件失败', | |
icon: 'none', | |
}) | |
console.log('error: ' + error); | |
}, { | |
region: 'SCN', | |
domain: 'https://img.wittcism.com', | |
uptokenURL: 'https://wittcism.com/backend/api/v1/upload_token_for_wechat', | |
}, (progress) => {}) | |
}, | |
}) |
Author
1c7
commented
Nov 4, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment