发现csdn上的人少了,PHP版微信支付通过STATE传自定义参数问题,不知道有大神不

hondely 2018-01-24 05:30:17
首先我的demo是已经调试好的,没有问题
接着我自己自定义了一个表单网页,用来提交total_fee以及其他参数的

<form action="http://www.test.cn/Wxpay/example/jsapi.php" method="post">
<input id="total_fee" value="55"></input>
<input type="submit"/>
</form>

然后在jsapi.php中得到total_fee

$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;
}

但是获得的total_fee始终是null,
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe688d529fee63f02&redirect_uri=http%3A%2F%2Fwww.test.cn%2FWxpay%2Fexample%2Fjsapi.php&response_type=code&scope=snsapi_base&state={%22total_fee%22:%22%22}#wechat_redirect
...全文
682 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
okgef 2018-02-02
  • 打赏
  • 举报
回复
这个版块的人更人呀
hondely 2018-01-24
  • 打赏
  • 举报
回复
还是自己动手丰衣足食啊,post没有传值过去,把下面的id改为name 问题解决了

<form action="http://www.test.cn/Wxpay/example/jsapi.php"  method="post">
    <input id="total_fee" value="55"></input>
    <input type="submit"/>
</form>
hondely 2018-01-24
  • 打赏
  • 举报
回复
URL解码后是这样的 https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe688d529fee63f02&redirect_uri=http://www.test.cn/Wxpay/example/jsapi.php&response_type=code&scope=snsapi_base&state={"total_fee":""}#wechat_redirect 难道是我第一个$curFee没有post得到数据吗????

3,143

社区成员

发帖
与我相关
我的任务
社区描述
微信开发即微信公众平台开发,将企业信息、服务、活动等内容通过微信网页的方式进行表现,通过二次开发可以将公众账号由一个媒体型营销工具转化成提供服务的产品。
社区管理员
  • 微信开发
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧