1<?php
2require_once('vendor/autoload.php');
3use WeChatPay\Builder;
4use WeChatPay\Crypto\Rsa;
5use WeChatPay\Util\PemUtil;
6
7
8$merchantId = '190000****';
9
10$merchantPrivateKeyFilePath = 'file:///path/to/merchant/apiclient_key.pem';
11$merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);
12
13$merchantCertificateSerial = '3775B6A45ACD588826D15E583A95F5DD********';
14
15$platformCertificateFilePath = 'file:///path/to/wechatpay/cert.pem';
16$platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);
17
18$platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificateFilePath);
19
20$instance = Builder::factory([
21 'mchid' => $merchantId,
22 'serial' => $merchantCertificateSerial,
23 'privateKey' => $merchantPrivateKeyInstance,
24 'certs' => [
25 $platformCertificateSerial => $platformPublicKeyInstance,
26 ],
27]);
28
29$resp = $instance
30 ->chain('v3/pay/transactions/native')
31 ->post(['json' => [
32 'mchid' => '1900006XXX',
33 'out_trade_no' => 'native12177525012014070332333',
34 'appid' => 'wxdace645e0bc2cXXX',
35 'description' => 'Image形象店-深圳腾大-QQ公仔',
36 'notify_url' => 'https://weixin.qq.com/',
37 'amount' => [
38 'total' => 1,
39 'currency' => 'CNY'
40 ],
41 ]]);
42echo $resp->getBody(), PHP_EOL;