|
导读微信小程序,简称小程序,英文名Mini Program,是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或搜一下即可打开应用。小程序是一种不用下载就能使用的应用,也是一... 微信小程序,简称小程序,英文名Mini Program,是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或搜一下即可打开应用。小程序是一种不用下载就能使用的应用,也是一项门槛非常高的创新,经过将近两年的发展,已经构造了新的小程序开发环境和开发者生态。 本篇文章给大家带来的内容是关于微信小程序如何使用webview调用微信扫一扫的功能,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。我们在做web开发时是按照web开发流程进行的,当需要快速将web项目移植到小程序里面,就需要用到小程序提供的webview组件。关于它的好处以及开发平台配置大家可以按照微信公众平台进行配置 前端逻辑: 具体流程是: ①html页面初始化时向我们的后台请求获取基本配置数据,参数就是当前页面url路径,包括带参部分。 具体代码展示<!-- 这个地方是在加载配置,实际页面中是页面渲渲染时通过“java后台jssdkconfig”接口从我们的后台获取参数,然后赋值给下面对应的字段”-->
<script type="text/javascript">
wx.config({
debug: true,//是否开启调试
appId: 'wx97d97ea93ef96606',//小程序appid
timestamp: '1534925207',//时间搓,单位秒
nonceStr: 'HT5Ab5moviaVdp7XegNnRBivrETgPmu2',//随机字符串
signature: 'd73acd8eec5a4c1a6a86c7e0517bedff78e72fd9',//签名md5
jsApiList: ['startRecord','stopRecord','playVoice','uploadVoice','downloadVoice','onVoiceRecordEnd','translateVoice','downloadVoice', 'onMenuShareTimeline','onMenuShareAppMessage','scanQRCode','getLocation','chooseImage','getLocalImgData','uploadImage']//当前html需要用到的接口
});
</script>后台JAVA逻辑: 处理流程: ①页面第一次请求获取配置信息,后台使用微信接口计算得到配置信息,并存起来,然后返回给前端 后台代码: /**
* webview——JSSDK使用配置信息获取
*/
@ResponseBody
@RequestMapping(value = "User/GetJsSdk_Config")
public Map<String, Object> GetJsSdk_Config(@RequestBody HashMap<String, Object> data, HttpSession session)
throws KeyStoreException, NoSuchAlgorithmException, CertificateException, Exception {
Map<String, Object> resultmap = new HashMap<String, Object>();
User user = (User) session.getAttribute("user");
if (user == null) {
resultmap.put("state", false);
resultmap.put("message", "未登录或登录超时");
return resultmap;
}
if (data.get("url") == null) {
resultmap.put("state", false);
resultmap.put("message", "参数不全");
return resultmap;
}
String url = data.get("url").toString();
Map<String, Object> one_jassdkcofig = AllJssdkConfig.TheconfigBeoVerdue(url);
if (one_jassdkcofig != null)// 如果当前页面配置信息还未过期
{
resultmap.put("sate", true);
resultmap.put("message", "");
resultmap.put("beta", one_jassdkcofig.get("beta"));
resultmap.put("debug", one_jassdkcofig.get("debug"));// 是否开启调试
resultmap.put("appId", one_jassdkcofig.get("appId"));// 公众号的appid
resultmap.put("timestamp", one_jassdkcofig.get("timestamp"));// 时间搓、秒
resultmap.put("nonceStr", one_jassdkcofig.get("nonceStr"));// 随即字符
resultmap.put("signature", one_jassdkcofig.get("signature"));// sha1加密码
resultmap.put("jsApiList", "所有需要用到的接口");// 需要使用的接口
System.out.println("找到配置!不用计算");
System.out.println(resultmap);
return resultmap;
}
String token = user_wxAPI.GetInstance().get_jssdk_accesstoken();
String ticket = user_wxAPI.GetInstance().get_jssdk_ticket(token);
resultmap = user_wxAPI.GetInstance().get_jssdk_config(ticket,url);
if (resultmap!=null) {
resultmap.put("sate", true);
resultmap.put("message", "");
AllJssdkConfig.SaveOneConfig(url, resultmap);// 更新jasdk数组配置
System.out.println("没有找到配置!重新计算");
System.out.println(resultmap);
return resultmap;
} else {
resultmap=new HashMap<String, Object>();
resultmap.put("sate", false);
resultmap.put("message", "后台获取jssdk_ticket出错");
return resultmap;
}
}相关推荐: 微信开发 - 微信v3扫码支付二返回的notify.php怎么接收回调的值 分享微信扫码支付开发遇到问题及解决方案-附Ecshop微信支付插件_php实例 以上就是微信小程序如何使用webview调用微信扫一扫的功能的详细内容,更多请关注php中文网其它相关文章! 小程序是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或者搜一下即可打开应用。 |
温馨提示:喜欢本站的话,请收藏一下本站!