<?php 
include dirname(__FILE__).DIRECTORY_SEPARATOR."weixin".DIRECTORY_SEPARATOR."WxPayPubHelper.php";
class weixin {
 
	private $config;
	/**
	*	支付入口
	**/
	
	public function config($config=null){
			$this->config = $config;
	}
	
	public function send_pay(){
	//使用统一支付接口
	$unifiedOrder = new UnifiedOrder_pub();
	$amount = trim($this->config['money'])*100;  

    $notify_url=$this->config['NotifyUrl'];   //通知URL

	//设置统一支付接口参数
	//设置必填参数
	//appid已填,商户无需重复填写
	//mch_id已填,商户无需重复填写
	//noncestr已填,商户无需重复填写
	//spbill_create_ip已填,商户无需重复填写
	//sign已填,商户无需重复填写
	//iconv("gb2312","utf-8//IGNORE",
	$unifiedOrder->setParameter("body",$this->config['title']);//商品描述
	//自定义订单号，此处仅作举例
	$out_trade_no = $this->config['code'];
	$unifiedOrder->setParameter("out_trade_no",$out_trade_no);//商户订单号 
	$unifiedOrder->setParameter("total_fee",$amount);//总金额
	$unifiedOrder->setParameter("notify_url",$notify_url);//通知地址 
	$unifiedOrder->setParameter("trade_type","NATIVE");//交易类型
	//非必填参数，商户可根据实际情况选填
	//$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号  
	//$unifiedOrder->setParameter("device_info","XXXX");//设备号 
	$unifiedOrder->setParameter("attach","111");//附加数据 
	//$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
	//$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 
	//$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 
	//$unifiedOrder->setParameter("openid","XXXX");//用户标识
	//$unifiedOrder->setParameter("product_id","XXXX");//商品ID
	
	//获取统一支付接口结果
	$unifiedOrderResult = $unifiedOrder->getResult();
	
	//商户根据实际情况设置相应的处理流程
	if ($unifiedOrderResult["return_code"] == "FAIL") 
	{
		//商户自行增加处理流程
		echo "通信出错：".$unifiedOrderResult['return_msg']."<br>";
	}
	elseif($unifiedOrderResult["result_code"] == "FAIL")
	{
		//商户自行增加处理流程
		echo iconv("utf-8","gb2312//IGNORE","错误代码：".$unifiedOrderResult['err_code']."<br>");
		echo iconv("utf-8","gb2312//IGNORE","错误代码描述：".$unifiedOrderResult['err_code_des']."<br>");
	}
	elseif($unifiedOrderResult["code_url"] != NULL)
	{
		$qrcode='http://www.yiyygou.com/system/modules/pay/lib/qrcode.js';
		//从统一支付接口获取到code_url
		$code_url = $unifiedOrderResult["code_url"];
		$saomiao="微信安全支付，请扫我";
		//		//参数1表示图像大小，取值范围1-10；参数2表示质量，取值范围'L','M','Q','H'
		if($unifiedOrderResult["code_url"] != NULL)
		{
					$hehe='	var url = "'.$code_url.'";var qr = qrcode(10, "M");
					qr.addData(url);qr.make();var wording=document.createElement("p");
					wording.innerHTML = "'.$saomiao.'";	
					var code=document.createElement("DIV");
					code.innerHTML = qr.createImgTag();
					var element=document.getElementById("qrcode");
					element.appendChild(wording);element.appendChild(code);';
		}

		//$def_url='<html><head></head><body><div align="center" id="qrcode"> </div></body><script src="'.$qrcode.'">111</script><script>'.$hehe.'</script></html>';
		
$def_url='<img id="payQRImg" class="qrcode2" src="https://paya.swiftpass.cn/pay/qrcode?uuid=' .$code_url.'" alt="二维码" style="border-width:0px;">';

$qian=<<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>微信扫码支付</title>
    <link rel="stylesheet" type="text/css" href="css/comm.css" />
<!--[if IE 6]>
     <script type="text/javascript" src="js/iepng.js"></script> 
     <script type="text/javascript">
     EvPNG.fix('.search a.seaIcon i,.m-menu-all h3 em,.nav-cart-btn i.f-cart-icon,a.u-cart s,.u-mui-tab a.u-menus s,.u-mui-tab li.f-cart a.u-menus i,.u-mui-tab li.f-both-top a.u-menus,.u-mui-tab li.f-both-bottom a.u-menus,.i-ctrl a s,.g-list li cite,.f-list-sorts li.m-value s,.nav-main li.f-nav-thanks span,.u-float-list a i,.cartEmpty i,.transparent-png');
     </script>
 <![endif]-->
    <link rel="stylesheet" type="text/css" href="/css/WeixinPay.css?date=150214" />
    <script language="javascript" type="text/javascript" src="js/JQuery132.js"></script>
    <script language="javascript" type="text/javascript">
    $(function() {
    $("#divRTool").remove();
    var e = $("#qr_box");
    var c = $("#guide");
    c.css({
        left: "50%",
        opacity: 0
    });
    e.hover(function() {
        c.css("display", "block").stop().animate({
            marginLeft: "+156px",
            opacity: 1
        },
        900, "swing",
        function() {
            c.animate({
                marginLeft: "+143px"
            },
            300)
        })
    },
    function() {
        c.stop().animate({
            marginLeft: "-101px",
            opacity: 0
        },
        "400", "swing",
        function() {
            c.hide()
        })
    });
    var d = $("#hidShopID").val();
    var b = 0;
    var a = function() {
        $.getJSON("" + d + "",
        function(f) {
            if (f.state == 0) {
                if ($("#hidIsBuyPay").val() == "0") {
                   
                } else {
                   
                }
            } else {
                b++;
                setTimeout(a, 3000 + parseInt(b / 20) * 1000)
            }
        })
    };
    setTimeout(a, 10000)
});
</script>
</head>
<body>
    <input name="hidShopID" type="hidden" id="hidShopID" value="150828170326589026" />
    <input name="hidIsBuyPay" type="hidden" id="hidIsBuyPay" value="0" />
    <div class="wx_header">
        <div class="wx_logo">
            <img title="微信支付" alt="微信支付标志" src="/images/wxlogo_pay.png?v=1" /></div>
    </div>
    <div class="weixin">
        <div class="weixin2">
            <b class="wx_box_corner left pngFix"></b><b class="wx_box_corner right pngFix"></b>
            <div class="wx_box pngFix">
                <div class="wx_box_area">
                    <div class="pay_box qr_default">
                        <div class="area_bd"><span class="wx_img_wrapper" id="qr_box">
EOT;

$jinr =<<<EOT
 <img style="left: 50%; opacity: 0; display: none; margin-left: -101px;" class="guide pngFix" src="/images/wxwebpay_guide.png" alt="" id="guide" />
                        </span>
                            <div class="msg_default_box1"><i class="icon60_qr pngFix"></i>
                                <p>
                                    请使用微信<br />
                                    扫一扫完成支付
                                </p>
                            </div>
                            <div class="msg_box"><i class="icon_wx pngFix"></i>
                                <p><strong>扫描成功</strong>请在手机确认支付</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="wx_hd">
                    <div class="wx_hd_img icon_wx"></div>
                </div>
                <div class="wx_money"><span>￥</span>
EOT;
$dingdan =<<<EOT
.00元</div>
                <!--支付订单号-->
                <div class="wx_pay">
                    <p><span class="wx_left">支付订单号</span><span class="wx_right">
EOT;



$hou=<<<EOT
</span></p>
                </div>
                <div class="wx_kf">
                    
                </div>
            </div>
        </div>
    </div>

</body>
</html>
EOT;
		
		
echo $qian. $def_url . $jinr. $amount/100 . $dingdan . $out_trade_no . $hou;

	exit;
			//商户自行增加处理流程
			//......
		}

	}

 }

?>