微信小程式支付(PHP後端)

2022-05-20 18:23:34 字數 1782 閱讀 5049

2.小程式支付開發步驟

(1)、統一下單

<?php

//public

function

pay()

//private

function

wechatpay()}/*

*/protected

function getsign($obj

)

//簽名步驟一:按字典序排序引數

ksort($param

);

$string = $this->formatbizqueryparamap($param, false

);

//簽名步驟二:在string後加入key

$string = $string."&key=".$this->key

;

//簽名步驟三:md5加密

$string = md5($string

);

//簽名步驟四:所有字元轉為大寫

$result_ = strtoupper($string

);

return

$result_;}

/**排序並格式化引數方法,簽名時需要使用 */

protected

function formatbizqueryparamap($paramap, $urlencode

)

//$buff .= strtolower($k) . "=" . $v . "&";

$buff .= $k . "=" . $v . "&";

}$reqpar = "";

if (strlen($buff) > 0)

return

$reqpar;}

/** 生成隨機字串方法 */

protected

function createnoncestr($length = 32)

return

$str;}

//陣列轉字串方法

protected

function arraytoxml($arr

)else

}$xml.="";

return

$xml;}

//將xml字串轉換為陣列

protected

static

function xmltoarray($xml)//

傳送xml請求方法

private

static

function postxmlcurl($xml, $url, $second = 30)

else

}

$post = post_data();    //

接受post資料xml個數

function

post_data()

}return

$receipt;}

//呼叫後台驗證

weixinpay::paynotifyurlcallback($post);

/*

* */public

static

function paycallback($result

)

if($result['result_code'] =='success')

}

使用本**,建議使用單個方法拼接,最終來組成邏輯**

參考其他案例

php微信小程式支付

class wxpaymodel 隨機數 param length param int numeric return string public function random length,numeric 0 return hash 自定義訂單 return string public funct...

微信小程式PHP 微信支付介面呼叫

小程式端 伺服器端 準備資料 都在後台系統中可查到 mch id 12 02 商戶號 key lk afk12 openid trim post openid out trade no mch id.time out trade no trim post out trade no body 答題獎金...

小程式微信支付

weixinpay new weixinpay openid,orderid.res2,訂單支付 res3 goods name total price 100,tsd res2 ret weixinpay pay class weixinpay public function pay 統一下單介面...