php微信支付实现
1.下载微信官方支付包 在这里插入图片描述  放到public下
然后 config 下 建一个 pay.php
<?php
return [
'wechatPay' => [
'app_id' => 'appid',
'mch_id' => '*********',
'key' => '*********',
'cert_path' => public_path().'/WeChat/cert/apiclient_cert.pem',
'key_path' => public_path().'/WeChat/cert/apiclient_key.pem',
'notify_url' => '**********异步回调',
]
];
随后 封装一下 Bases 创建一下一会有用
<?php
namespace App\Api\Bases;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as SonBaseController;
class CommonController extends SonBaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $pay;
public function __construct()
{
$this->pay = config('pay');
}
}
随后
public function wxPay($order_number,$total_fee=1)
{
include 'phpqrcode.php';
$config = $this->pay['wechatPay'];
$app = Factory::payment($config);
$result = $app->order->unify([
'body' => '社区团购',
'out_trade_no' =>time(),
'total_fee' =>$total_fee,
'notify_url' => '**************',
'trade_type' => 'NATIVE',
]);
$value =$result['code_url'];
$errorCorrectionLevel = 'L';
$matrixPointSize = 6;
$naem = rand(1111,9999).".jpg";
\QRcode::png($value, $naem, $errorCorrectionLevel, $matrixPointSize, 2);
$naem = '/'.$naem;
echo "<img src=$naem alt=''>";
}
顺带生成二维码 下载第三方类库 gitee下载 放到框架的vender目录中,注意名字为phpqrcode   生成普通二维码 样式  代码
public function view()
{
include 'phpqrcode.php';
$value = 'http://www.baoyuan.site';
$errorCorrectionLevel = 'L';
$matrixPointSize = 6;
$naem = rand(1111,9999).".jpg";
\QRcode::png($value, $naem, $errorCorrectionLevel, $matrixPointSize, 2);
$naem = "/".$naem;
echo "<img src=$naem alt=''>";
}
生成Logo二维码 样式
 
public function view()
{
include 'phpqrcode.php';
$value = 'http://www.baoyuan.site';
$errorCorrectionLevel = 'L';
$matrixPointSize = 6;
$name = rand(11111,99999).".png";
\QRcode::png($value, $name, $errorCorrectionLevel, $matrixPointSize, 2);
$logo = '1.jpg';
$QR = $name;
if ($logo !== FALSE) {
$QR = imagecreatefromstring(file_get_contents($QR));
$logo = imagecreatefromstring(file_get_contents($logo));
$QR_width = imagesx($QR);
$QR_height = imagesy($QR);
$logo_width = imagesx($logo);
$logo_height = imagesy($logo);
$logo_qr_width = $QR_width / 5;
$scale = $logo_width / $logo_qr_width;
$logo_qr_height = $logo_height / $scale;
$from_width = ($QR_width - $logo_qr_width) / 2;
imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,
$logo_qr_height, $logo_width, $logo_height);
}
$resimg = rand(11111,99999).".png";
imagepng($QR, $resimg);
$resimg = "/".$resimg;
echo "<img src=$resimg alt=''>";
}
此代码图片会出现在public根目录下需要改改路径哦
转载: https://xb00uop636.feishu.cn/docs/doccnTceVRmMKFkGVYL6RlUnnSf#
|