增加微信H5支付

给系统(只适合版本6.0)增加微信H5支付,系统原本是没有H5支付,只有微信扫码支付和微信公众号支付

1、先在met_pay_config表中,增加H5支付参数,9=H5支付

2、在系统中,浏览器在手机状态下增加微信H5支付  

路径:\app\system\pay\web\include\class      interface_pay.class.php

  public function get_pay_list() {
    global $_M;
		$return = array();
		$query = "SELECT * FROM {$_M['table'][pay_config]} WHERE name='payment_type' and lang='{$_M['lang']}'";
		$payment_type = DB::get_one($query);
		$list = explode('|', $payment_type['value']);
		$url = "{$_M['url']['site']}pay/app.php?paytype=";
		if($this->is_weixin()){//微信端
			if(strstr($payment_type['value'], '6')){
				$openId = $this->weixinopenId();
				$return['weixin_h5']['have'] = 1;
				$return['weixin_h5']['url'] = $url.'6';
				$return['weixin_h5']['check_url'] = "{$_M['url']['site']}pay/orderquery.php?paytype=1&out_trade_no=";
			}
		}else if($this->is_mobile()){//是移动端,就出现下面这些支付方式1
			if(strstr($payment_type['value'], '3')){
				$return['alipay']['have'] = 1;
				$return['alipay']['url'] = $url.'3';
			}

			if(strstr($payment_type['value'], '5')){
				$return['paypal']['have'] = 1;
				$return['paypal']['url'] = $url.'5';
			}
			
			if(strstr($payment_type['value'], '4')){
				$return['upay']['have'] = 1;
				$return['upay']['url'] = $url.'4';
			}
//			if(strstr($payment_type['value'], '6')){//微信公众号支付
//				//$openId = $this->weixinopenId();
//				$return['weixin_h5']['have'] = 1;
//				$return['weixin_h5']['url'] = $url.'6';
//				$return['weixin_h5']['check_url'] = "{$_M['url']['site']}pay/orderquery.php?paytype=1&out_trade_no=";
//			}
			if(strstr($payment_type['value'], '9')){//微信H5支付
				//$out_trade_no=date('YmdHis').rand(1, 100000);
				$return['weixin_jspay']['have'] = 1;
				$return['weixin_jspay']['url'] = $url.'9';
				//$return['weixin_jspay']['check_url'] = "{$_M['url']['site']}pay/orderquery.php?paytype=9&out_trade_no=";
			}
			
		}else{//其它端,比如PC
			if(strstr($payment_type['value'], '1')){
				$return['weixin']['have'] = 1;
				$return['weixin']['url'] = $url.'1';
				$return['weixin']['check_url'] = "{$_M['url']['site']}pay/orderquery.php?paytype=1&out_trade_no=";
			}

			if(strstr($payment_type['value'], '2')){
				$return['tenpay']['have'] = 1;
				$return['tenpay']['url'] = $url.'2';
			}

			if(strstr($payment_type['value'], '3')){
				$return['alipay']['have'] = 1;
				$return['alipay']['url'] = $url.'3';
			}

			if(strstr($payment_type['value'], '5')){
				$return['paypal']['have'] = 1;
				$return['paypal']['url'] = $url.'5';
			}

			if(strstr($payment_type['value'], '4')){
				$return['upay']['have'] = 1;
				$return['upay']['url'] = $url.'4';
			}

			/*if(strstr($payment_type['value'], '7')){
				$return['jd']['have'] = 1;
				$return['jd']['url'] = $url.'7';
			}*/
		}
		return $return;
    }

3、在前端模块中增加H5支付链接

\app\app\shop\web\templates\met      shop_pay_order.php

<!--
EOT;
}
if($pay_list['weixin_h5']){
echo <<<EOT
-->
						<li class="text-xs-center pay-order-weixin">
							<a class="block cover pay-online payment-weixin-h5" href="javascript:void(0)" data-url="{$pay_list['weixin_h5']['url']}" data-check_url="{$pay_list['weixin_h5']['check_url']}"><img src="{$_M[url][shop_ui]}static/img/weixinpay.png" class='img-fluid inline-block'/></a>
						</li>
						<!-- End Modal -->
						<!-- Modal -->
						<div class="modal fade modal-primary" id="payment-weixin-h5-modal" aria-hidden="true" role="dialog" tabindex="-1">
							<div class="modal-dialog modal-center modal-sm">
								<div class="h-100 vertical-align text-xs-center order-loader"><div class="loader vertical-align-middle loader-default"></div></div>
							</div>
						</div>
						<!-- End Modal -->
<!--
EOT;
}
if($pay_list['weixin_jspay']){//微信H5支付
echo <<<EOT
-->
						<li class="text-xs-center pay-order-weixin">
							<a class="block cover pay-online payment-weixin-jspay" href="javascript:void(0)" data-url="{$pay_list['weixin_jspay']['url']}" data-check_url="{$pay_list['weixin_jspay']['check_url']}{$order[orderid]}"><img src="{$_M[url][shop_ui]}static/img/weixinpay.png" class='img-fluid inline-block'/></a>
						</li>
						<!-- End Modal -->
						<!-- Modal -->
						<div class="modal fade modal-primary" id="payment-weixin-h5-modal" aria-hidden="true" role="dialog" tabindex="-1">
							<div class="modal-dialog modal-center modal-sm">
								<div class="h-100 vertical-align text-xs-center order-loader"><div class="loader vertical-align-middle loader-default"></div></div>
							</div>
						</div>
						<!-- End Modal -->

<!--
EOT;
}
if($pay_list['upay']){
echo <<<EOT
-->

4、支付的时候转到H5支付

\app\system\pay\web    app.class.php

5、在支付类中增加H5类

\app\system\pay\web         wxpay.class.php

    /**
     * 微信H5支付
     * @param String(128) body           商品描述(商品或支付单简要描述)
     * @param String(127) attach         附加数据(在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据)
     * @param String(32)  out_trade_no   商户订单号(商户支付的订单号由商户自定义生成,长度不大于32位、可包含字母)
     * @param Int         total_fee      总金额(订单总金额,原始单位为分,只能为整数。可后台处理为“元”为单位)
     * @param String(32)  goods_tag      商品标记(商品标记,代金券或立减优惠功能的参数)
     * @param String(32)  product_id     商品ID(trade_type=NATIVE/MWEB,此参数必传。此id为二维码中包含的商品ID,商户自行定义)
     * @param String(32)  SetScene_info  场景信息(trade_type=MWEB,此参数必传。该字段用于上报支付的场景信息,针对H5支付有以下三种场景)
     * 1,IOS移动应用
     * 2,安卓移动应用
     * 3,WAP网站应用
            {"h5_info": //h5支付固定传"h5_info"
            {"type": "",  //场景类型
            "wap_url": "",//WAP网站URL地址
            "wap_name": ""  //WAP 网站名
            }
            }
     */
    public static function webH5($date) {
        global $_M;
        $notify_url = is_strinclude($_M['url']['pay_notify'], 'localhost') ? '' : $_M['url']['pay_notify'];
        //$redirect_url = $_M['url']['order_query']."out_trade_no={$date['out_trade_no']}&paytype=9&return=1";
		$redirect_url = $date['return_url']."out_trade_no={$date['out_trade_no']}&paytype=9&return=1";
		//var_dump($date['return_url']);die;
		

        $notify     = new NativePay();
        $input      = new WxPayUnifiedOrder();
		

        $info = array();
        $info['type'] = "Wap";
        $info['wap_url'] = $_M['url']['site'];
        $info['wap_name'] = $date['subject'];
        //$info['wap_name'] = "adsadas";
        $infoarr = array();
        $infoarr['h5_info'] = $info;
        $scene_info = jsonencode($infoarr);
        #$scene_info = '{"h5_info":{"type":"Wap","wap_url":"http://met6.com/","wap_name":"adsadas"}}';//测试

        $cip = $_SERVER['REMOTE_ADDR'];
        if(!$cip){
            $cip = getenv('REMOTE_ADDR');
        }
		
		//$input->GetAppid();
		//var_dump($values['appid']);die;

        $input->SetBody($date['body']);
		
        //$input->SetAttach($date['attach']);
        $input->SetOut_trade_no($date['out_trade_no']);
        $input->SetTotal_fee($date['total_fee']*100);
        $input->SetTime_start(date("YmdHis"));
        $input->SetTime_expire(date("YmdHis", time() + 600));
        $input->SetGoods_tag($date['goods_tag']);
        $input->SetNotify_url($notify_url);
        $input->SetTrade_type("MWEB");              //JSAPI 公众号支付 | NATIVE 扫码支付 | APP APP支付
       // $input->SetProduct_id($date['product_id']);
       // $input->SetScene_info($scene_info);
	

        //$result    = $notify->GetPayUrl($input);
		$result = WxPayApi::unifiedOrder($input);
		
	
        $url       = $result["mweb_url"];
        //$url       = $url."&redirect_url=".urlencode($redirect_url);
		$url       = $url."&redirect_url=".$redirect_url;
		//var_dump($url);die;

        header("Location:$url");
    }

微信文件放到这个文件夹:\app\system\pay\web\wxpay\

猜你喜欢

转载自blog.csdn.net/haibo0668/article/details/81273502