ouranoshong / wx-pay-api
WXPay library build on office sdk
v0.4.8
2019-09-25 09:28 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: ^7.1
README
wxpay_v3 api library
more detail see wx office document
Usage
Installation
$ composer require ouranoshong/wx-pay-api
UnifiedOrderPay 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();
Notify Entity
// 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 Entity
// reply success message to wx server echo \WXPay\WXPayReply::createSuccessReply(); // reply fail messge to wx server echo \WXPay\WXPayReply::createFailReply('fail message');
Functions
// 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);