
1<?php
2
3require_once('vendor/autoload.php');
4
5use WeChatPay\Builder;
6use WeChatPay\Crypto\Rsa;
7
8
9
10
11$merchantId = '190000****';
12
13
14$merchantPrivateKeyFilePath = 'file:///path/to/merchant/apiclient_key.pem';
15$merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);
16
17
18$merchantCertificateSerial = '3775B6A45ACD588826D15E583A95F5DD********';
19
20
21$platformPublicKeyFilePath = 'file:///path/to/wechatpay/publickey.pem';
22$twoPlatformPublicKeyInstance = Rsa::from($platformPublicKeyFilePath, Rsa::KEY_TYPE_PUBLIC);
23
24
25
26$platformPublicKeyId = 'PUB_KEY_ID_01142321349124100000000000********';
27
28
29$instance = Builder::factory([
30 'mchid' => $merchantId,
31 'serial' => $merchantCertificateSerial,
32 'privateKey' => $merchantPrivateKeyInstance,
33 'certs' => [
34 $platformPublicKeyId => $twoPlatformPublicKeyInstance,
35 ],
36]);
37
38
39$resp = $instance -> chain('v3/pay/transactions/native') -> post(['json' => [
40 'mchid' => '1900006XXX',
41 'out_trade_no' => 'native12177525012014070332333',
42 'appid' => 'wxdace645e0bc2cXXX',
43 'description' => 'Image形象店-深圳腾大-QQ公仔',
44 'notify_url' => 'https://weixin.qq.com/',
45 'amount' => [
46 'total' => 1,
47 'currency' => 'CNY'
48 ],
49 ],
50
51 'headers' => [
52 'Wechatpay-Serial' => '134912410000000000000xxxxxxx',
53 ],
54]);
55
56print_r(json_decode((string) $resp->getBody(), true));
57
58{
59 "code": "RESOURCE_NOT_EXISTS",
60 "message": "无可用的平台证书,请在商户平台-API安全申请使用微信支付公钥。"
61}
62