当前位置:   article > 正文

uniapp开发的跳转到小程序_sweixin.launchminiprogram

sweixin.launchminiprogram

uniapp开发的h5跳转到小程序
https://www.cnblogs.com/xiaojianwei/p/16352698.html
官方:使用 URL Scheme 打开小程序
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/url-scheme.html

 链接代码

<a href="weixin://dl/business/?appid=wxx******&path=pages/order/order&query=&env_version=release"  class="but"> 打开weixin </a>

条件:微信必须实名认证、通过备案 ,设置了 “明文scheme拉起此小程序”


通过weixin://dl/business/?t=打开微信小程序
https://blog.csdn.net/m0_46156566/article/details/128917461

 

第一步,通过微信接口(https://api.weixin.qq.com/cgi-bin/token)获取小程序access_token
微信官方文档

第二步,通过微信接口(https://api.weixin.qq.com/wxa/generatescheme)获取小程序跳转链接weixin://dl/business/?t=
微信官方文档
我这里用的uni-app,所以请求用的uni.request,其他的同理,比如ajax和axios,不多赘述

  1. // 第一步获取token
  2. uni.request({
  3. method: "GET",
  4. // 这里的appid写你需要跳转的小程序的appid,secret秘钥也一样,grant_type=client_credential是固定的参数,不用改
  5. url: "https://api.weixin.qq.com/cgi-bin/token?appid=wxe109dd058as8sdf88&secret=9eb3d6dec783bc55sdfs32sdf2f2aa0&grant_type=client_credential",
  6. success: (res1) => {
  7. alert("获取token成功");
  8. console.log(res1.data);
  9. //2步获取小程序跳转链接
  10. uni.request({
  11. method: "POST",
  12. // access_token就是请求上一个接口拿到的回调结果
  13. url:
  14. "https://api.weixin.qq.com/wxa/generatescheme?access_token=" + res1.data.access_token,
  15. data: {
  16. // path跳转到的小程序目标页面,query跳转需要携带参数,在目标页面onload里面接收options里面,其他参数固定,获取看文档了解
  17. jump_wxa: {
  18. path: "/app/test/test",
  19. query: "url=" + urls,
  20. env_version: "trial", // 正式版为"release",体验版为"trial",开发版为"develop"
  21. },
  22. is_expire: true,
  23. expire_type: 1,
  24. expire_interval: 1,
  25. // env_version: "trial",
  26. },
  27. success: (res2) => {
  28. alert("获取小程序跳转链接1");
  29. console.log(res2.data);
  30. let a = document.createElement("a"); //创建一个a标签元素
  31. a.href = res2.data.openlink; //设置跳转地址
  32. document.body.appendChild(a); //加入
  33. a.click(); //触发点击跳转
  34. document.body.removeChild(a);删除元素
  35. },
  36. fail:(err) =>{
  37. alert('获取微信跳转链接失败')
  38. alert(JSON.stringify(err))
  39. }
  40. });
  41. },
  42. fail:(err) =>{
  43. alert('获取微信token失败')
  44. alert(JSON.stringify(err))
  45. }
  46. });

 

uniapp拉起小程序

在uniapp中拉起小程序,可以使用官方提供的API uni.navigateToMiniProgram。以下是一个简单的示例代码:

  1. uni.navigateToMiniProgram({
  2. appId: '目标小程序的appid', // 小程序的appid
  3. path: 'pages/index/index', // 打开的页面路径,可选
  4. extraData: {
  5. // 需要传递给小程序的数据,可选
  6. },
  7. success(res) {
  8. // 打开成功的回调,可选
  9. console.log('打开成功');
  10. },
  11. fail(err) {
  12. // 打开失败的回调,可选
  13. console.log('打开失败', err);
  14. }
  15. });

确保在调用这个API之前,已经在uniapp的manifest.json中配置了相应的权限,并且appid是正确的。

  1. // manifest.json 中配置示例
  2. "mp-weixin": {
  3. "usingComponents": true,
  4. "navigateToMiniProgramAppIdList": [
  5. "目标小程序的appid"
  6. ]
  7. }

 在调用这个API之前,请确保你已经遵循了微信小程序的相关指导和要求,并且已经获取了相应的权限。如果是其他平台的小程序,请查阅对应平台的开发文档,因为不同平台的API调用可能会有所不同。

uni-app生成的app支持跳转微信小程序

uni-app生成的app支持跳转微信小程序
https://ask.dcloud.net.cn/question/67412

参考链接:http://www.html5plus.org/doc/zh_cn/share.html#plus.share.ShareService.launchMiniProgram
注意:需要先在manifest.json中配置【微信消息及朋友圈】


参考代码:

  1. plus.share.getServices(function(res){
  2. var sweixin = null;
  3. for(var i=0;i<res.length;i++){
  4. var t = res[i];
  5. if(t.id == 'weixin'){
  6. sweixin = t;
  7. }
  8. }
  9. if(sweixin){
  10. sweixin.launchMiniProgram({
  11. id: '原始id',
  12. path: 'pages/index/index?phone=' + UserID,
  13. type: 0
  14. }):plus.nativeUI.alert('当前环境不支持微信操作!');
  15. }
  16. },function(res){
  17. console.log(JSON.stringify(res));
  18. });

uniapp开发的APP唤起微信打开小程序
https://blog.csdn.net/superlover_/article/details/89382540

uni-app开发的APP跳转到微信小程序需要调用H5+的原生界面控件。

注意事项:

用到了分享功能,在打包原生应用时,需要注意:首先勾选权限配置,manifest.json->App 模块权限配置->Share。然后,manifest.json->App SDK 配置->分享,按照提示填写微信分享的信息(微信开放平台,不是微信公众平台)。
因为涉及到第三方 SDK 的配置,需要打包自定义基座进行测试。真机运行自定义基座包使用说明
需要在微信开放平台开启APP跳转小程序,并管理相应的小程序
 

  1. <template>
  2. <view class="center">
  3. <view class="text" @click="checkWeChat">跳转到小程序</view>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. sweixin: null
  11. }
  12. },
  13. onLoad() {
  14. this.getPlus()
  15. },
  16. methods: {
  17. getPlus() {
  18. //获取当前显示的webview
  19. var pages = getCurrentPages()
  20. var page = pages[pages.length - 1]
  21. var currentWebview = page.$getAppWebview()
  22. //调用H5+APP的扩展API
  23. var shares=null;
  24. let that = this
  25. var pusher = plus.share.getServices(function(s){
  26. shares={};
  27. for(var i in s){
  28. var t=s[i];
  29. shares[t.id]=t;
  30. }
  31. that.sweixin=shares['weixin'];
  32. }, function(e){
  33. console.log("获取分享服务列表失败:"+e.message);
  34. });
  35. //放入当前的webview
  36. currentWebview.append(pusher);
  37. },
  38. checkWeChat() {
  39. //调用微信小程序
  40. this.sweixin.launchMiniProgram({
  41. id:'gh_244-------' //要跳转小程序的原始ID
  42. })
  43. }
  44. }
  45. }
  46. </script>
  1. /*
  2. *唤起跳转微信小程序
  3. *miniId 小程序id
  4. *miniPath 小程序页面路径
  5. */
  6. function LaunchMiniProgram (miniId,miniPath){
  7. // #ifdef APP-PLUS
  8. //获取终端支持的分享通道列表
  9. plus.share.getServices(function(s){
  10. let sweixin = null;
  11. for(let i=0;i<s.length;i++){
  12. if(s[i].id == 'weixin'){
  13. sweixin = s[i];
  14. }
  15. }
  16. //判断是否有微信
  17. if(sweixin){
  18. console.log('调起小程序',s)
  19. //唤起微信跳转小程序
  20. sweixin.launchMiniProgram({
  21. id:miniId,
  22. path:miniPath
  23. },function(){
  24. return true;
  25. },function(e){
  26. console.log("微信唤起失败",e);
  27. uni.showToast({
  28. title:'微信唤起失败,请检查是否有微信应用',
  29. icon:'none'
  30. })
  31. return false;
  32. })
  33. }else{
  34. uni.showToast({
  35. title:'微信唤起失败,请检查是否有微信应用',
  36. icon:'none',
  37. duration:3000
  38. })
  39. return false;
  40. }
  41. }, function(e){
  42. console.log("微信唤起失败",e);
  43. uni.showToast({
  44. title:'微信唤起失败,请重试',
  45. icon:'none',
  46. duration:3000
  47. })
  48. return false;
  49. });
  50. // #endif
  51. // #ifdef MP-BAIDU || MP-TOUTIAO || MP-WEIXIN || MP-ALIPAY || MP-QQ
  52. uni.navigateToMiniProgram({
  53. appId: miniId,
  54. path: miniPath,
  55. success(res) {
  56. return true
  57. },
  58. fail(res){
  59. uni.showToast({
  60. title:'跳转小程序失败',
  61. icon:'none',
  62. duration:3000
  63. })
  64. console.log('跳转小程序失败',res)
  65. return false;
  66. }
  67. })
  68. // #endif
  69. }

微信拉起半屏API

  1. openmini: function (){
  2. let mchid='19905033266'; // 商户号
  3. let amount='1.01';
  4. let ordercode=Date.parse(new Date());
  5. console.log(mchid, ordercode, amount)
  6. let param = 'mchid='+mchid+'&openType=1&autoPay=1&notify_url=https%3A%2F%2Fwxpay.eptjt.com%2FLKT%2Fnotify_ftpay.php&goodName=数字易货商品&mer_order_no='+ordercode+'&amount='+amount;
  7. wx.openEmbeddedMiniProgram({
  8. appId: 'wx5507008900fb4e7f',// 你要打开的小程序appid
  9. path: 'pages/Index/index?' + param, // 打开的页面路径,如果为空则打开首页
  10. extraData: {
  11. // mchid:mchid,
  12. // openType:1,
  13. // autoPay:1,
  14. // notify_url:'https%3A%2F%2Fwxpay.eptjt.com%2FLKT%2Fnotify_ftpay.php',
  15. // mer_order_no: ordercode,
  16. // goodName:'数字易货商品',
  17. // amount:amount,
  18. },// 需要传递给目标小程序的数据
  19. envVersion: 'develop',// 要打开的小程序版本 develop 开发版 trial 体验版 release 正式版
  20. success(res) {
  21. // 打开成功
  22. console.log(res)
  23. // wx.showToast({
  24. // title: res.data.err,
  25. // duration: 2000
  26. // });
  27. },
  28. fail(e) {
  29. // 打开失败
  30. console.log(e)
  31. },
  32. })
  33. },

Android应用签名查看工具没有MD5值的解决方法

由于高版本java 移除了 这些 Disable MD5 or MD2 signed jars
https://www.java.com/en/jre-jdk-cryptoroadmap.html

于是输出了一下我的本地java环境

  1. > java -version
  2. java version "15.0.1" 2020-10-20
  3. Java(TM) SE Runtime Environment (build 15.0.1+9-18)
  4. Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
  5. >

演示如何将SHA1值转换为MD5值

  1. import java.security.MessageDigest;
  2. import java.security.NoSuchAlgorithmException;
  3. public class MD5Utils {
  4. public static String calculateMD5(String input) {
  5. try {
  6. MessageDigest md = MessageDigest.getInstance("MD5");
  7. byte[] byteData = md.digest(input.getBytes());
  8. StringBuilder sb = new StringBuilder();
  9. for (byte b : byteData) {
  10. sb.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
  11. }
  12. return sb.toString();
  13. } catch (NoSuchAlgorithmException e) {
  14. e.printStackTrace();
  15. return null;
  16. }
  17. }
  18. public static void main(String[] args) {
  19. String sha1 = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  20. String md5 = calculateMD5(sha1);
  21. System.out.println("MD5: " + md5);
  22. }
  23. }

在上面的示例代码中,我们将SHA1值替换为实际的值,然后运行程序,即可得到对应的MD5值输出

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/988782
推荐阅读