PHP WeChat payment URL redirection get code problem

Source: Internet
Author: User
Tags openid
Payment of the demo into my frame, my is OOP, the official demo is the original writing, I wrote a method to preprocess the payment, the first step to get code when the Rediect_url redirect address returned to call me this preprocessing method, found that the session could not be used, which resulted in the way to get the order information into the method to execute the payment template

The code is as follows:

Enter the order payment template

function Dopay (er = ")
{
if ($pay = = ' Weixin ')
{
$this->weixinpay ()

}$this->dispaly('dopay.html');

}

function Weixinpay ()
{

 if(!isset($_GET['code']))    {        //触发返回code码        $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL);        Header("Location: $url");          //注意这个重定向,是个巨大的坑,一旦请求,redidtc_url调用的是本方法,此时SESSION失效         //跳转之后访问这个方法但是,这个方法没调用去模板的方法,所以没法显示模板,之后我想用SESSION保存    }    else    {        //获取code码,以获取openid        $code   = $_GET['code'];        $jsApi->setCode($code);        $openid = $jsApi->getOpenId();    }    // 预支付代码。。。。。    //按理说已经成功预支付了,应该去显示模板了,但是由于此时是redidtc_url直接外网访问此方法的,所以上面的index方法来不及等本方法执行完毕    就没法调用模板了,问题来了 index -> weixinpay(预处理) -> 显示支付模板     weixinpay 去调用了,由于需要获取code,不得不调用自己,但是调用后,SESSION失效,如何去index方法呢?     注意:index方法是需要order_id参数的,不如报错

}

Reply content:

Payment of the demo into my frame, my is OOP, the official demo is the original writing, I wrote a method to preprocess the payment, the first step to get code when the Rediect_url redirect address returned to call me this preprocessing method, found that the session could not be used, which resulted in the way to get the order information into the method to execute the payment template

The code is as follows:

Enter the order payment template

function Dopay (er = ")
{
if ($pay = = ' Weixin ')
{
$this->weixinpay ()

}$this->dispaly('dopay.html');

}

function Weixinpay ()
{

 if(!isset($_GET['code']))    {        //触发返回code码        $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL);        Header("Location: $url");          //注意这个重定向,是个巨大的坑,一旦请求,redidtc_url调用的是本方法,此时SESSION失效         //跳转之后访问这个方法但是,这个方法没调用去模板的方法,所以没法显示模板,之后我想用SESSION保存    }    else    {        //获取code码,以获取openid        $code   = $_GET['code'];        $jsApi->setCode($code);        $openid = $jsApi->getOpenId();    }    // 预支付代码。。。。。    //按理说已经成功预支付了,应该去显示模板了,但是由于此时是redidtc_url直接外网访问此方法的,所以上面的index方法来不及等本方法执行完毕    就没法调用模板了,问题来了 index -> weixinpay(预处理) -> 显示支付模板     weixinpay 去调用了,由于需要获取code,不得不调用自己,但是调用后,SESSION失效,如何去index方法呢?     注意:index方法是需要order_id参数的,不如报错

}

JS Public Number Payment steps: 1. Back-end Generation JS Package 2. Front-end origination payment 3. After the payment is completed, the page JS callback 4. Backend callback; The middle does not involve the landlord said the code operation

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.