[Api] can small letter pays a lot of people, but do not know how refund

The article that you may like, later small make up meeting one by one to release

    [Api] PHP and date of small letter public pay, very simple [Api] letter of Duan Wei of PHP development APP pays a function, learn [Api] seeing PHP is how to realize small letter to sweep a code to pay. [Api] how is seeing PHP to realize small letter enterprise to pay of individual pocket money [Api] is seeing PHP how to realize small letter H5 to pay? [Api] seeing PHP is how to realize small letter to carry those who show a function

Pre-construction:

Refund operation is to should small letter pays of course above all, ability can have the business of refund, it is the Demo of use government below. There also is a lot of to write and enclose Demo again on the net, probably more good with concise, but I still am not advocated with, the reason is as follows:

(1) likelihood the function is not complete, probably he just realized small letter to pay, but still order of inquiry of application refund, inquiry refund, order, cancel waits for business function may be your follow-up need, if you rely on the SDK of great mind convenient, if have new demand for service, you are muddled forced;

(2) safe consideration, involve pay involve money, must want special security. Official SDK although I also spit groove, but can compare safety relatively at least, rescript again, although did not see a problem temporarily, but in case have flaw bad.

A the most important a SDK that still uses the government to offer is medium kind of Refund() means that provides in file WxPay.Api.php will come true

Code is as follows:

/ ** * * applies for refund, the Out_trade_no in WxPayRefund, Transaction_id fills at least and when * Out_refund_no, Total_fee, Refund_fee, Op_user_id does not need to fill * @param WxPayRefund $inputObj * @param Int $timeOut * @throws WxPayException * @return to succeed to fill parameter * Appid, Mchid, Spbill_create_ip, Nonce_str surely, return, other cast unusual */ Public Static Function Refund($inputObj, $timeOut = 6){$url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; // detects fill parameter If(surely! $inputObj->IsOut_trade_noSet() &&! In interface of application of refund of $inputObj->IsTransaction_idSet()) {Throw New WxPayException(" , out_trade_no, Transaction_id fills at least! ") ; }else If(! In interface of application of refund of $inputObj->IsOut_refund_noSet()){Throw New WxPayException(" , lack fill parameter Out_refund_no surely! ") ; }else If(! In interface of application of refund of $inputObj->IsTotal_feeSet()){Throw New WxPayException(" , lack fill parameter Total_fee surely! ") ; }else If(! In interface of application of refund of $inputObj->IsRefund_feeSet()){Throw New WxPayException(" , lack fill parameter Refund_fee surely! ") ; }else If(! In interface of application of refund of $inputObj->IsOp_user_idSet()){Throw New WxPayException(" , lack fill parameter Op_user_id surely! ") ; } $inputObj->SetAppid(WxPayConfig: ID $inputObj->SetMch_id(WxPayConfig of date of APPID);// public Zhang: MCHID);// business door date $inputObj->SetNonce_str(self: $xml = $inputObj->ToXml(); $startTimeStamp = Self of autograph of $inputObj->SetSign();// of GetNonceStr());// random string: GetMillisecond();// requests to begin time $response = Self: PostXmlCurl($xml, $url, true, $timeOut); $result = WxPayResults: Init($response); Self: ReportCostTime($url, $startTimeStamp, the newspaper requests to cost time Return $result; } on $result);//

Official method, written very clear need what parameter, still have a few must parameter SDK has helped us fill neat, I enclose this method afresh, facilitate call in the project:

/ ** * is returned when ID * @return of order of * @param String $order_id of small letter refund is successful (Array type) , other cast the Require_once APP_ROOT below the Api list that my SDK puts unusual */ Function WxRefund($order_id){// below project root catalog. "/Api/wxpay/lib/WxPay.Api.php"; // inquires order, according to order the data inside undertakes refund $order = M('order')->where(array('id'=>$order_id, 'is_refund'=>2, 'order_status'=>1))->find(); $merchid = WxPayConfig: MCHID; If(! Him $order) Return False; $input = New WxPayRefund(); $input->SetOut_trade_no($order['order_sn']); // the bugle call of order running water that government of small letter of order order $input->SetTransaction_id($order['transaction_id']); // makes, have in paying a success return order of $input->SetTotal_fee($order['total_price']); // of odd numbers of $input->SetOut_refund_no(getrand_num(true)); // refund to mark a price amount, the unit is total amount of minute of $input->SetRefund_fee($order['total_price']); // refund, order total amount, the unit is cent, can be integral $input->SetOp_user_id($merchid); $result = WxPayApi only: Refund($input); // refund is operated / / this File_put_contents is to use the refund result that examines a server to return to checked to be able to be deleted / / File_put_contents(APP_ROOT. '/Api/wxpay/logs/log3.txt' , arrayToXml($result) , FILE_APPEND); Return $result; }

Here returns array to had been compared, OK and direct judgement is handled. The method calls more simple:

/ / $result = WxRefund($order_id); // of small letter refund this File_put_contents is to use the refund result that examines a server to return to checked to be able to be deleted / / File_put_contents(APP_ROOT. '/Api/wxpay/logs/log4.txt' , arrayToXml($result) , FILE_APPEND); If(($result['return_code' ]=='SUCCESS') &&($result['result_code' ]==}else If(($result['return_code' of success of 'SUCCESS')){// refund]=='FAIL') | | ($result['result_code' ]==Does 'FAIL')){// refund fail / / reason $reason = (empty($result['err_code_des']) ? $result['return_msg']:$} of failure of Result['err_code_des']); }else{//

Refund returns successfully as follows:

[Api] can small letter pays a lot of people, but do not know how refund

Above is an article entire content, those who have study and experience communication is OK attention is little make up. Technical issue can be discussed together with communication, if you are of PHP, small make up also can pull you to take small letter skill group, communication and study!

未经允许不得转载:News » [Api] can small letter pays a lot of people, but do not know how refund