PHP的H5页面在外部浏览器调起微信小程序
2022/5/5 20:13:28
本文主要是介绍PHP的H5页面在外部浏览器调起微信小程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<?php
//$appid 公众号配置的appid, $secret 公众号配置的secret,$info 给query的参数
public function appletpayment($appid,$secret,$info){
//获取access_token
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret;
$data =$this->curl_get($url);
$access_token = json_decode($data,true)['access_token'];
//通过scheme码进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带query。path为空时会跳转小程序主页。
$post_data['jump_wxa']['path'] = '';
//通过scheme码进入小程序时的query,最大1024个字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~
$post_data['jump_wxa']['query'] = 'orderID='.$info['orderID'].'&payType='.$info['payType'];
$post_data = json_encode($post_data);
// 生成的URL Scheme
$post_url = 'https://api.weixin.qq.com/wxa/generatescheme?access_token='.$access_token;
$result =$this->curl_post($post_url,$post_data);
$jumpUrl = json_decode($result,true)['openlink'];
return $jumpUrl;
}
//curl get方式
public function curl_get($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
//curl post方式
public function curl_post($url, $post_data = '', $timeout = 3000)
{
header("Content-type:text/html;charset=utf-8");
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, false);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
这篇关于PHP的H5页面在外部浏览器调起微信小程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29env: php: no such file or directory
- 2024-03-01php foreach break
- 2024-02-26Exception参数 php-icode9专业技术文章分享
- 2023-12-30PHP文件批量上传-icode9专业技术文章分享
- 2023-12-30thinkphp6 withJoin-icode9专业技术文章分享
- 2023-12-27MagicArray:像php一样,让Go业务代码不再卷!
- 2023-11-18centos7编译安装PHP教程。
- 2023-11-18centos7编译安装phpMyAdmin教程。
- 2023-10-13唱衰这么多年,PHP 仍然还是你大爷!
- 2023-07-25PHP8,性能更好,语法更好,类型安全更完善