赞
踩
项目中遇到,除了官方文档外没查到有用的资料,现在发一下自己写的
官方文档: 获取 URL Scheme | 微信开放文档
前端部分:
<html lang="zh"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>商城小程序</title> </head> <body> <p style="text-align: center">跳转中.....</p> </body> <script> location.href = "weixin://dl/business/?t=6yJIhZkWr8t"; </script> </html>
php代码:
public function getScheme() { $user = $this->auth->getUser(); $appid = '你得appid'; $secret = '小程序secret'; //path是要跳转的小城页面地址,query为要携带的参数 $body = ['jump_wxa'=>['path'=>'/pages/index/index','query'=>'pid=1']]; $tokenurl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret; $data = file_get_contents($tokenurl); $data = json_decode($data, true); $token = $data['access_token']; $url = "https://api.weixin.qq.com/wxa/generatescheme?access_token=" . $token; $data = $this->curl_post($url, null, $body); dump($data); }
function curl_post($url,$herder,$body){ //一般框架都会自带GuzzleHttp,没有的请手动安装,或者利用curl post请求 $client = new \GuzzleHttp\Client(); try { $pram = $client->post($url,[ 'headers'=>$herder, 'json'=>$body, ]); $content = json_decode($pram->getBody()->getContents(),true); return $content; }catch (ErrorException $exception){ return $exception->getCode(); } }
//贴一下返回结果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。