微信支付 APP 支付方式的伺服器端處理程式

2021-07-22 10:06:48 字數 3208 閱讀 6025

這裡只說第一點,統一下單程式。統一下單的伺服器端處理,就是要生成預支付訂單的id 

除錯了一下,有一些坑,整理**如下:

<?php 

header("content-type: text/html; charset=utf-8");

include

"../../config.php";

$orderbody = "test商品";

$tade_no = "abc_" . time();

$total_fee = 1;

$wxpayhelper = new wxpayhelper();

$response = $wxpayhelper->getprepayorder($orderbody, $tade_no, $total_fee);

p_val("---response----");

p_val($response);

p_val("---拿到prepayid再次簽名----");

$x = $wxpayhelper->getorder($response['prepay_id']);

p_val($x);

/** * convert xml string to php array - useful to get a serializable value

* *@param string $xmlstr

*@return array

*@author adrien aka gaarf

*/class

wxpayhelper

//獲取預支付訂單

public

function

getprepayorder

($body, $out_trade_no, $total_fee)

//執行第二次簽名,才能返回給客戶端使用

public

function

getorder

($prepayid)

/*生成簽名

*/function

getsign

($obj)

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

ksort($parameters);

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

//echo "【string】 =".$string."

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

$string = $string."&key=".$this->config['api_key'];

echo"";

//簽名步驟三:md5加密

$result_ = strtoupper(md5($string));

return

$result_;

}//獲取指定長度的隨機字串

function

getrandchar

($length)

return

$str;

}//陣列轉xml

function

arraytoxml

($arr)

else

$xml.=".$val."]]>.$key.">";

}$xml.="";

return

$xml;

}//post https請求,curlopt_postfields xml格式

function

postxmlcurl

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

else }/*

獲取當前伺服器的ip

}//將陣列轉成uri字串

function

formatbizqueryparamap

($paramap, $urlencode)

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

}$reqpar;

if (strlen($buff) > 0)

return

$reqpar;

}/**

xml轉成陣列

*/function

xmlstr_to_array

($xmlstr)

function

domnode_to_array

($node)

$output[$t] = $v;

}elseif($v)

}if(is_array($output))

$output['@attributes'] = $a;

}foreach ($output

as$t => $v) }}

break;

}return

$output;

}}?>

注意點: 

①post必須支援https,且引數格式必須是xml 

②sign簽名的引數包括所有$data,除了自己 

③$data[「spbill_create_ip」]不能隨便設定乙個ip位址,不要以為除錯方便隨便設定,結果返回簽名錯誤坑你沒商量。一定要是程式執行時所在的伺服器ip位址,所以使用get_client_ip()獲取就好。 

④api_key是需要自己進入商戶平台設定的,郵件不會發給你哦 

使用隨機程式產生32個字元就好了 

⑤相當重要的是:返回給各戶端發起支付時,還要進行二次簽名$wxpayhelper->getorder

頂 3

php微信支付之APP支付方法

wechatapppay檔案 如下 class wechatapppay extends wechatpaybase 建立app支付最終返回引數 throws exception return multitype string null public function createapppaydat...

php微信支付之APP支付方法

wechatapppay檔案 如下 複製 如下 phpnamespace common services wechatpay class wechatapppay extends wechatpaybase 建立app支付最終返回引數 throws exception return multityp...

前端微信支付方法

首先上標籤 最主要的是這一行 img v if soupass true?true false src this.base finance wxpay precreate order?username this.username userid this.userid rechargeamount t...