微信 之小程式支付

2022-06-08 14:51:10 字數 3258 閱讀 8469

二、小程式支付的互動圖

三、在商戶平台新增授權申請單

四、在小程式後台 m-a授權

七、後台引數配置

八、具體**實

'package' => 小程式傳給後台的prepay_id,

'signtype' => 'md5',];

wx.requestpayment(,  '

fail

':function

(res){},  '

complete

':function

(res){}

})

附小程式支付文件:

下面是具體**實現:

class

weixinpay

public

function

pay()

//統一下單介面

private

function

unifiedorder()

private

static

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

else

}//陣列轉換成xml

private

function arraytoxml($arr

)

else

}$xml .= "";

return

$xml

; }

//xml轉換成陣列

private

function xmltoarray($xml

)

//private

function

//作用:產生隨機字串,不長於32位

private

function createnoncestr($length = 32)

return

$str

; }

//作用:生成簽名

private

function getsign($obj

)

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

ksort($parameters

);

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

);

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

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

;

//簽名步驟三:md5加密

$string = md5($string

);

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

$result_ = strtoupper($string

);

return

$result_

; }

///作用:格式化引數,簽名過程需要使用

// 接受不到引數可以使用file_get_contents("php://input"); php高版本中$globals好像已經被廢棄了

if (empty($postxml

)) //

將xml格式轉換成陣列

function xmltoarray($xml

) $attr = xmltoarray($postxml

);$total_fee = $attr['total_fee'];

$open_id = $attr['openid'];

$itemid = $attr['out_trade_no'];

$time = $attr['time_end'];

//你的**邏輯。。。

獲取小程式頁面引數:

);$parameters = $weixinpay->pay();

將$parameters傳給小程式:

wx.requestpayment();

},'fail': function

(res) ,

'complete': function

(res)

});

小程式微信支付

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

微信小程式支付

class wxpay protected mch id protected key protected openid protected out trade no protected body protected total fee protected notifyurl protected un...

微信小程式微信支付流程

1.小程式呼叫wx.login獲取登入憑證code wx.login 無請求引數 返回code 有效期5分鐘 wx.login 2.小程式通過code獲取openid 向介面位址 請求引數 返回引數 openid 使用者唯一標識 session key 回話金鑰 3.小程式向服務端傳送openid,...