Blogger Information
Blog 9
fans 0
comment 0
visits 8402
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP的H5页面在外部浏览器调起微信小程序
洒脱艸的博客
Original
369 people have browsed it
<?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;
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post