生成微信小程序分享二维码
微信小程序官方开放的二维码的接口,其中有一个是生成小程序二维码的,还有一个是圆形的小程序码,我这里就用php生成二维码。
完整代码:
public function share($product_id, $user_id) {
//首先要获取Access_token 。注意:access_token只有2小时有效期,所以要缓存最好,避免重复请求
$access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . config('appid') . "&secret=" . config('secret');
$json = $this->httpRequest($access_token);
$json = json_decode($json, true);
//width是二维码宽度
$qcode = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" . $json['access_token'];
$param = json_encode(array("path" => "/pages/public/product/product?id=" . $product_id . "&parent_id=" . $user_id . "&product_id=" . $product_id, "width&