php 跳出微信内置浏览器

<?php

//判断是否是微信浏览器
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if (strpos($user_agent, 'MicroMessenger') === false) {
    $isweixin = false;
} else {
    // 微信浏览器,允许访问
    $isweixin = true;
}


//判断手机型号
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);

//分别进行判断
if(strpos($agent, 'iphone') || strpos($agent, 'ipad'))
{
    $type = 'ios';
}

if(strpos($agent, 'android'))
{
    $type = 'android';
}

//判断是微信浏览器并且是ios(ios跳不出去)
if($isweixin == true && $type == 'ios'){
    header('Location: ');
    exit();
}



$preorderApi = "https://www.baidu.com";//这里是要跳转的网址
$mch_id = ""; //商户号
$key = "";//商户密钥
$body="vip";//商品
$total_fee="100";//价格
$spbill_create_ip="";//客户端ip
$notify_url="http://www.baidu.com/";//通知地址
$redirect_url="http://www.baidu.com/";//跳转前端地址
$trade_type="WX";//支付方式
$out_trade_no=time();

$signstr="body=".$body."&mch_id=".$mch_id."&notify_url=".$notify_url."&out_trade_no=".$out_trade_no."&redirect_url=".$redirect_url."&spbill_create_ip=".$spbill_create_ip."&total_fee=".$total_fee."&trade_type=".$trade_type."&key=".$key;

$sign = md5($signstr);

$params["sign"] = $sign;//签名
$params["mch_id"] = $mch_id;
$params["body"] = $body;
$params["total_fee"] = $total_fee;
$params["spbill_create_ip"] = $spbill_create_ip;
$params["notify_url"] = $notify_url;
$params["redirect_url"] = $redirect_url;
$params["trade_type"] = $trade_type;
$params["out_trade_no"] = $out_trade_no;

$ret =$preorderApi . "?" . http_build_query($params);

$data = json_encode(array('mid'=>"wx1029", 'url'=>$ret));   
$url_rets="http://jd-mall.cn/api/get.php"; //内付接口
$posts=http_request($url_rets,$data);
$json=json_decode($posts,true);
$url_d="http://jd-mall.cn/index.php?url=".$json['pay'];

header("Location:".$url_d);    
exit; 


//https请求(支持GET和POST)
function http_request($url, $data = null){
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  if (!empty($data)){
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  }
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  $output = curl_exec($curl);
  if($errno = curl_errno($curl)) {
    $error_message = curl_strerror($errno);
    echo "cURL error ({$errno}):\n {$error_message}";
  }
  curl_close($curl);
  return $output;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值