基于获取小程序码保存到手机的需求,使用tp5进行后台的处理,下面是获取小程序码的方法:

//二维码生成
public function code()
{
    $user_id = $this->uid;
    $user = Users::where("user_id = $user_id")->find();
    if($user['code_img']){
        return $this->success($user['code_img']);
    }else{
        //获取token
        $appID = "XXX";
        $appSecret = "XXXXXXXXX";
        $tokenUrl= "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&app>

 

function send_post($url, $post_data,$method='POST') {
    $postdata = http_build_query($post_data);
    $options = array(
        'http' => array(
            'method' => $method, //or GET
            'header' => 'Content-type:application/x-www-form-urlencoded',
            'content' => $postdata,
            'timeout' => 15 * 60 // 超时时间(单位:s
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return $result;
}

function api_notice_increment($url,$data)
{
    $curl = curl_init();
    $a = strlen($data);
    $header = array("Content-Type: application/json; charset=utf-8","Content-Length: $a");
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl,CURLOPT_POST,1);
    curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $res = curl_exec($curl);
    curl_close($curl);
    return $res;

}

以上就是获取小程序码的方法

 

 

相关文章:

  • 2021-06-14
  • 2021-09-23
  • 2021-05-18
  • 2021-10-11
  • 2021-10-26
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-14
  • 2021-12-23
  • 2021-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-12-01
  • 2021-06-02
相关资源
相似解决方案