ouranoshong / wx-pay-api
基于官方SDK构建的WXPay库
v0.4.8
2019-09-25 09:28 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: ^7.1
README
wxpay_v3 API库
更多详情请参阅微信官方文档
用法
安装
$ composer require ouranoshong/wx-pay-api
统一订单支付API
$client = new \WXPay\WXPayClient(); $config = new \WXPay\WXPayConfig(); $config->appId = ''; $config->mchId = ''; $config->key = ''; $config->notifyUrl = ''; $request = new \WXPay\Request\UnifiedOrderRequest(); $request->setBody(''); $request->setOutTradeNo(''); $request->setTotalFee(); $request->setSpBillCreateIp(''); $request->setOpenid(''); // or set other api parameter $request->setXXX(); $response = new \WXPay\Response\UnifiedOrderResponse(); $client->setConfiguration($config); $client->setHandlerName(\WXPay\Handler\UnifiedOrderHandler::class); $client->handle($request, $response); // print all response default var_dump(json_encode($response->getResult(), JSON_PRETTY_PRINT)); // get specify reponse message (in camlcase) $response->getXXX();
通知实体
// don't check signature $notify = \WXPay\WXPayNotify::createFromXml('<xml>...</xml>'); // check signature $notify = \WXPay\WXPayNotify::createFromXml('<xml>...</xml>', 'key'); // get signature from wei xin server push $notify->sign; // get something else $nofiy->getXXX();
回复实体
// reply success message to wx server echo \WXPay\WXPayReply::createSuccessReply(); // reply fail messge to wx server echo \WXPay\WXPayReply::createFailReply('fail message');
函数
// sign `$data` with `$key` use md5 \WXPay\signature($data, $key); // generate nonce string \WXPay\generate_nonce_str($len); // convert asocc array to xml \WXPay\convert_arr_to_xml($arr); // convert xml to asocc array \WXPay\convert_xml_to_arr($xml);