在微信扫码支付中,需要在线显示支付的二维码图片,因此记录下改操作,以备不时之需。
以下是在API中的生成二维码图片的方法。
public function payImg(){
$url = $this->request->param('url','');
if(empty($url)) $this->result([],0,'参数错误','json');
$level = $this->request->param('level','L');
$size = $this->request->param('size',6);
import('phpqrcode/phpqrcode', EXTEND_PATH,'.php');
$object = new \QRcode();
$errorCorrectionLevel =intval($level) ;//容错级别
$matrixPointSize = intval($size);//生成图片大小
$img = $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
echo $img;die;
}
在扫码支付下单完成后,需要将返回的支付链接以二维码的方式在前端展示,则前端代码为(tp5框架中)
<!-- 微信支付 -->
<div class="pay-weixin">
<div class="p-w-hd">微信支付</div>