微信支付-----jsapi

//php页面----yii2.0框架
public function actionJsapi(){
        $this->layout=false;
        $total_fee=0.02;//$_POST['total_fee'];
        $body="常奥康";//$_Get['body'];
        //①、获取用户openid
        $tools = new \JsApiPay();
        $access_token=$this->access_token;
        $openId = $tools->GetOpenid($access_token);
        //②、统一下单
        $input = new \WxPayUnifiedOrder();
        $input->SetBody($body);//商品名称
        $input->SetAttach("test");
        $input->SetOut_trade_no(\WxPayConfig::MCHID.date("YmdHis"));
        $input->SetTotal_fee($total_fee*100);//商品价格
        $input->SetTime_start(date("YmdHis"));
        $input->SetTime_expire(date("YmdHis", time() + 600));
//        $input->SetGoods_tag("test");
        $input->SetNotify_url(\WxPayConfig::NOTIFY_URL);
        $input->SetTrade_type("JSAPI");
        $input->SetOpenid($openId);
        $order = \WxPayApi::unifiedOrder($input);
        $jsApiParameters =$tools->GetJsApiParameters($order);
//        $arr=json_decode($jsApiParameters,true);
//        $signature="jsapi_ticket=".$this->ticket."&noncestr=".$arr['nonceStr']."&timestamp=".$arr['timeStamp']."&url=http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
//        $arr['sigNature']=sha1($signature);
//        $jsApiParameters=json_encode($arr);
//        $url="http://app.mj0408.com/p3-10-3-1-1payment.html?p=".$jsApiParameters;
//        header("Location:".$url);
         return $this->render('jsapi',array('jsApiParameters'=>$jsApiParameters,'total_fee'=>$total_fee));
    }
//html页面

<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/> 
    <title>微信支付</title>
    <script type="text/javascript">
   //调用微信JS api 支付
   function jsApiCall()
   {
      WeixinJSBridge.invoke(
         'getBrandWCPayRequest',
         <?php echo $jsApiParameters; ?>,//php处理后接收的json数据
         function(res){
            WeixinJSBridge.log(res.err_msg);
            if(res.err_msg=='get_brand_wcpay_request:ok'){//如果支付成功
                location.href="http://app..com/p3-7-2pay_success.html";
                }else{//如果支付失败
                    location.href="http://admin..com/weixin/wxpay/jsapi.html";
                }
//          alert(res.err_msg);//cancel/ok;;;;;;;;get_brand_wcpay_request:ok
         }
      );
   }

   function callpay()
   {
      if (typeof WeixinJSBridge == "undefined"){
          alert(document.addEventListener);return;
          if( document.addEventListener ){
              document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
          }else if (document.attachEvent){
              document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
              document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
          }
      }else{
          jsApiCall();
      }
   }
   </script>

</head>
<body>
    <br/>
    <font color="#9ACD32"><b>该笔订单支付金额为<span style="color:#f00;font-size:50px"><?=$total_fee?></span></b></font><br/><br/>
   <div align="center">
      <button style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer;  color:white;  font-size:16px;" type="button" οnclick="callpay()" >立即支付</button>
   </div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值