物流货物送达拍照上传保存(vue)
https://res.wx.qq.com/open/js/jweixin-1.6.0.js 放index.html里
public function sign(){
$url = input('url','');
date_default_timezone_set("Asia/Shanghai");
$share=null;;
$jsapi_ticket="";
$token=$this->getToken('access_token');
$url="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=$token&type=jsapi";
$obj=json_decode(file_get_contents($url),true);
if(isset($obj['errcode'])&&$obj['errcode']=='40001'){
$token=$this->getNewToken('access_token');
$url="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=$token&type=jsapi";
$obj=json_decode(file_get_contents($url),true);
}
$jsapi_ticket=$obj['ticket'];
$noncestr=substr(md5(time().rand(1000,9999)),0,16);
$timestamp=time();
$stringSign="jsapi_ticket=$jsapi_ticket&noncestr=$noncestr×tamp=$timestamp&url=$url";
$signature=sha1($stringSign);
$res['signature']=$signature;
$res['noncestr']=$noncestr;
$res['timestamp']=$timestamp;
return json($res);
}
photo(){
let tis = this;
let url = window.location.href;
tis.$Api("wechat/sign", {url:url}, "post",false).then((res) => {
let o = res
wx.config({
debug: false,
appId: '11111111111111111',
timestamp: o["timestamp"],
nonceStr: o["noncestr"],
signature: o["signature"],
jsApiList: [
'chooseImage',
'uploadImage'
]
});
wx.error(function(res){
console.log(res)
});
wx.ready(function() {
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var localIds = res.localIds;
wx.getLocalImgData({
localId: localIds[0],
success: function (res) {
let localData = res.localData;
let imageBase64 = '';
if (localData.indexOf('data:image') == 0) {
imageBase64 = localData;
} else {
imageBase64 = 'data:image/jpeg;base64,' + localData.replace(/\n/g, '');
}
tis.upload(imageBase64);
}
});
}
});
});
});
},
upload(imageBase64){
let tis = this;
let a = imageBase64.split(',');
let b = atob(a[1]);
let c = b.length;
let u = new Uint8Array(c);
while (c--) {
u[c] = b.charCodeAt(c);
}
let file = new File([u], 'x.jpg', {type: a[0].match(/:(.*?);/)[1]})
tis.$Upd(file,function(r){
tis.order.delivery_image=r;
tis.$Api("order/addEdit", {orderid:tis.orderid,delivery_image:r}, "post").then((res) => {});
})
},