微信公众号(网页)调起拍照并上传

物流货物送达拍照上传保存(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&timestamp=$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) => {});
	})
},

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值