
2】自己登陆开发者工具,查看源码3】不是开发者,完全是别人的小程序就直接反编译过来,进行第二步的 *** 作4】企业小程序现在开放了h5外链,直接访问链接就能打开小程序。基仔
不论你是在app还是短信界面,都可以调起小程毕族序链接。我感觉应该是问的这个问题,就是想着把小程序链接提取出来,通过外链方式打开。可以参考我这个链接,直接就可以打开到微信小程序
class BaiDuAiBaseController extends BaseController{
private $appid
private $appKey
private $secretKey
public function __construct(){
$this->appid= config('api.baidu.appid')
$this->appKey = config('api.baidu.apikey')
$this->secretKey = config('api.baidu.secretkey')
}
//百度ai接口--文字识别--车牌号识别
public function getCarNumber($_imgurl,$_img=''){
$_token = $this->getToken()
$_url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate?access_token='.$_token
if($_img){
$_data = [
'image'=>$_img//图像数据,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式
]
}else{
$_data = [
'url'=>request()->domain().'/'.$_imgurl
]
}
$_res = json_decode(httpGet($_url,$_data),true)
/庆穗/TODO 此处只返回false没有终止,是因为程序执行流程需要,后期可能要改
if(isset($_res['error_msg'])) return false
return $_res['words_result']['number']
}
//获取token
private function getToken(){
if(cache('baidu_token')){
$_access_token = cache('baidu_token')
}else{
$_url = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id='.$this->appKey.'&client_secret='.$this->secretKey
$res = json_decode(httpGet($_url),true)
if(isset($res['error']))TApiException($res['error_description'])//终止程序并抛出异常
$_access_token = $res['access_token']
$_expires_in = $res['粗轮expires_in']
cache('baidu_token',$_access_token,($_expires_in-1000))//我喜欢少存1000秒,没有为什么,问就是癖好
}
return $_access_token
}
}
这是ThinkPhp5.1后端封装的百度AI接口类,getToken()获取凭证,getCarNumber()请求$_url 返回识别结果,这个是车牌号码识岩差信别,车型识别等其他接口大部分都一样,就换个请求地址$_url就行
//接口:
public function getImgCarNum(){
$_number = (new BaiDuAiBaseController())->getCarNumber(false,request()->param('img'))
return self::myShow('申请成功',['carNum'=>$_number])
}
小程序端正常request请求上面的接口就行,下面是微信小程序拍照识别功能
//拍照
goImgSearch(){
uni.chooseImage({
count:1,
sizeType: ['compressed'],//original 原图,compressed 压缩图
sourceType: ['album','camera'],//camera 相机 album相册
success:(r)=>{
console.log(r)
//执行识别车牌号码
this.img = r.tempFilePaths[0]
this.urlTobase64(r.tempFilePaths[0])
}
})
},
//识别车牌号码
urlTobase64(url){
uni.showLoading({
title:'拼命识别车牌中..'
})
//#ifdef MP-WEIXIN
uni.getFileSystemManager().readFile({
filePath: url, //选择图片时返回的路径
encoding: "base64",//这个是很重要的
success: res =>{ //成功的回调
//返回base64格式
let base64 = 'data:image/jpegbase64,' + res.data
//发送请求,识别车牌号码
this.$H.post('/getImgCarNum',{
img:base64 //图片数据
},{
token:true //必须登录
}).then((res)=>{
console.log(res.carNum)
if(!res.carNum){
uni.hideLoading()
return uni.showModal({
title:'识别失败',
content:'没能识别到车牌号码,请拍张清晰的图片再试哦,谢谢',
showCancel:false
})
}
uni.showToast({
title:'识别车牌成功',
icon:'none'
})
this.searchUser = res.carNum
this.userCarNum = res.carNum
uni.hideLoading()
}).catch((e)=>{
uni.hideLoading()
return uni.showModal({
title:'识别失败',
content:'没能识别到车牌号码,请拍张清晰的图片再试哦,谢谢',
showCancel:false
})
})
},
fail:(e)=>{
console.log(e)
}
})
//#endif
},
公众号添加网页链接的教程
微信公众号的运营者们你们的福利来弯毕卖啦
未认证的微信公众号可以埋逗添加外部链接啦!
1、首先,进入微信公众号后台,编辑素材的界面,点击“小程序”。
2、搜索小程序网页,并点击“下一步”。
3、小程序的路径改为:“数毕web?u= 网址”的格式,输入文字内容,点击”确定”即可。
例如:web?u=baidu.com。
若网址中有特殊字符=?等特殊字符,把网址通过转码工具,转为urlencode编码即可。
以上使用微信小程序“网页”能够在微信公众号中添加网页,希望能够帮到你。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)