3,143
社区成员
发帖
与我相关
我的任务
分享
<form action="http://www.test.cn/Wxpay/example/jsapi.php" method="post">
<input id="total_fee" value="55"></input>
<input type="submit"/>
</form>
$curFee=$_POST["total_fee"];
$tools = new JsApiPay();
$openId = $tools->GetOpenid($curFee);//$curFee传递给GetOpenid()函数进而传递给STATE
public function GetOpenid($total_fee)
{
//通过code获得openid
if (!isset($_GET['code'])){
//触发微信返回code码
$baseUrl = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING']);
$url = $this->__CreateOauthUrlForCode($baseUrl);
$state=json_encode(array(
"total_fee"=>"$total_fee"
));
$url=str_replace("STATE",$state,$url);
Header("Location: $url");
exit();
} else {
//获取code码,以获取openid
$code = $_GET['code'];
$openid = $this->getOpenidFromMp($code);
$state=$_GET['state'];
$state=str_replace("\\","",$state);
$param=json_decode($state,true);
$state["total_fee"]=$param['total_fee']*100;
return $openid;
}
<form action="http://www.test.cn/Wxpay/example/jsapi.php" method="post">
<input id="total_fee" value="55"></input>
<input type="submit"/>
</form>