throw new Exception($result[‘errmsg’],$result[‘errcode’]); } if ($XHpayConfig[‘is_pop_qrcode’]) { //获取二维码地址 $RiProPay = new RiProPay; $pay_qrcode_url = $RiProPay->_cao_get_xunhupay_qrcode($result); $iconstr = ‘[LT]img src=”‘.get_template_directory_uri()%20.%20’/assets/icons/alipay.png” class=”qr-pay”>’; $html_str = ‘[LT]div class=”qrcon”> [LT]h5> ‘.$iconstr.’ [LT]/h5> [LT]div class=”title”>支付宝扫码支付 ‘.$order_price.’ 元[LT]/div> [LT]div align=”center” class=”qrcode”> [LT]img src=”‘.$pay_qrcode_url.'”/> [LT]/div> [LT]div class=”bottom alipay”> 请使用支付宝扫一扫支付[LT]br>提示:若扫码支付失败,请重试[LT]br>或添加站长微信:1256069585 办理[LT]/br> [LT]/div> [LT]/div>’; echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘1’, ‘msg’ => $html_str, ‘img’ => $pay_qrcode_url, ‘num’ => $order_trade_no)); exit; }else{ echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘2’, ‘rurl’ => $result[‘url’], ‘qrcode’ => ”, ‘msg’ => $order_trade_no));exit; } } catch (Exception $e) { echo “errcode:{$e->getCode()},errmsg:{$e->getMessage()}”;exit; //TODO:处理支付调用异常的情况 } exit; } //讯虎支付 支付宝 if ($pay_type == 9) { require_once get_template_directory() . ‘/inc/class/xunhupay.class.php’; // 获取后台支付配置 $XHpayConfig = _cao(‘xunhupay_ali’); // 添加订单 ShopOrder if (!$ShopOrder->add($uid, $order_trade_no, $order_type, $order_price, $pay_type)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘订单创建失败’));exit; } $data=array( ‘mchid’ => $XHpayConfig[‘mchid’], ‘out_trade_no’ => $order_trade_no, ‘type’ => ‘alipay’, ‘total_fee’ => $order_price*100, ‘body’ => $order_name, ‘notify_url’ => get_template_directory_uri() . ‘/shop/xunhupay/notify4.php’, ‘nonce_str’ => str_shuffle(time()) ); $hashkey =$XHpayConfig[‘private_key’]; if(XH_Payment_Api::is_app_client()){ $data[‘redirect_url’]=get_template_directory_uri() . ‘/shop/xunhupay/return2.php’; $data[‘sign’] = XH_Payment_Api::generate_xh_hash_new($data,$hashkey); $pay_url = XH_Payment_Api::data_link(‘https://admin.xunhuweb.com/alipaycashier’, $data); $pay_url1 = htmlspecialchars_decode($pay_url,ENT_NOQUOTES); echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘2’, ‘rurl’ => $pay_url1, ‘qrcode’ => ”, ‘msg’ => $order_trade_no)); exit; } $data[‘sign’] = XH_Payment_Api::generate_xh_hash_new($data,$hashkey); $url = $XHpayConfig[‘url_do’].’/pay/payment’; try { $response = XH_Payment_Api::http_post_json($url, json_encode($data)); /** * 支付回调数据 * @var array( * order_id,//支付系统订单ID * url//支付跳转地址 * ) */ $result = $response?json_decode($response,true):null; if(!$result){ throw new Exception(‘Internal server error’,500); } $hash = XH_Payment_Api::generate_xh_hash_new($result,$hashkey); if(!isset( $result[‘sign’])|| $hash!=$result[‘sign’]){ throw new Exception(__(‘Invalid sign!’,XH_Wechat_Payment),40029); } if($result[‘err_code’]!=0){ throw new Exception($result[‘errmsg’],$result[‘errcode’]); } $pay_url =$result[‘code_url’]; //获取二维码地址 $pay_qrcode_url = getQrcode($pay_url); $iconstr = ‘[LT]img src=”‘.get_template_directory_uri()%20.%20’/assets/icons/alipay.png” class=”qr-pay”>’; $html_str = ‘[LT]div class=”qrcon”> [LT]h5> ‘.$iconstr.’ [LT]/h5> [LT]div class=”title”>支付宝扫码支付 ‘.$order_price.’ 元[LT]/div> [LT]div align=”center” class=”qrcode”> [LT]img src=”‘.$pay_qrcode_url.'”/> [LT]/div> [LT]div class=”bottom alipay”> 请使用支付宝扫一扫支付[LT]br>提示:若扫码支付失败,请重试[LT]br>或添加站长微信:1256069585 办理[LT]/br> [LT]/div> [LT]/div>’; echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘1’, ‘msg’ => $html_str, ‘img’ => $pay_qrcode_url, ‘num’ => $order_trade_no)); exit; } catch (Exception $e) { echo “errcode:{$e->getCode()},errmsg:{$e->getMessage()}”;exit; //TODO:处理支付调用异常的情况 } exit; } //讯虎支付 微信支付 if ($pay_type == 10) { $http_type = ((isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] == ‘on’) || (isset($_SERVER[‘HTTP_X_FORWARDED_PROTO’]) && $_SERVER[‘HTTP_X_FORWARDED_PROTO’] == ‘https’)) ? ‘https://’ : ‘http://’; require_once get_template_directory() . ‘/inc/class/xunhupay.class.php’; // 获取后台支付配置 $XHpayConfig = _cao(‘xunhupay_wx’); // 添加订单 ShopOrder if (!$ShopOrder->add($uid, $order_trade_no, $order_type, $order_price, $pay_type)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘订单创建失败’));exit; } $data=array( ‘mchid’ => $XHpayConfig[‘mchid’], ‘out_trade_no’ => $order_trade_no, ‘type’ => ‘wechat’, ‘total_fee’ => $order_price*100, ‘body’ => $order_name, ‘notify_url’ => get_template_directory_uri() . ‘/shop/xunhupay/notify3.php’, ‘nonce_str’ => str_shuffle(time()) ); $hashkey =$XHpayConfig[‘private_key’]; if(XH_Payment_Api::is_wechat_app()){ $data[‘redirect_url’]=get_template_directory_uri() . ‘/shop/xunhupay/return2.php’; $data[‘sign’] = XH_Payment_Api::generate_xh_hash_new($data,$hashkey); $pay_url = XH_Payment_Api::data_link(‘https://admin.xunhuweb.com/pay/cashier’,$data); $pay_url1 = htmlspecialchars_decode($pay_url,ENT_NOQUOTES); echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘2’, ‘rurl’ => $pay_url1, ‘qrcode’ => ”, ‘msg’ => $order_trade_no)); exit; } if(XH_Payment_Api::is_app_client()){ $url= get_template_directory_uri() . ‘/inc/xunhupay/h5.php?out_trade_no=’.$order_trade_no.’&total_fee=’.$order_price.’&title=’.$order_name.’&type=1′; echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘2’, ‘rurl’ => $url, ‘qrcode’ => ”, ‘msg’ => $order_trade_no)); exit; } $data[‘sign’] = XH_Payment_Api::generate_xh_hash_new($data,$hashkey); $url = $XHpayConfig[‘url_do’].’/pay/payment’; try { $response = XH_Payment_Api::http_post_json($url, json_encode($data)); /** * 支付回调数据 * @var array( * order_id,//支付系统订单ID * url//支付跳转地址 * ) */ $result = $response?json_decode($response,true):null; if(!$result){ throw new Exception(‘Internal server error’,500); } $sign = XH_Payment_Api::generate_xh_hash_new($result,$hashkey); if(!isset( $result[‘sign’])|| $sign!=$result[‘sign’]){ throw new Exception(__(‘Invalid sign!’,XH_Wechat_Payment),40029); } if($result[‘return_code’]!=’SUCCESS’){ throw new Exception($result[‘err_msg’],$result[‘err_code’]); } $url =$result[‘code_url’]; //获取二维码地址 $pay_qrcode_url = getQrcode($url); $iconstr = ‘[LT]img src=”‘.get_template_directory_uri()%20.%20’/assets/icons/weixin.png” class=”qr-pay”>’; $html_str = ‘[LT]div class=”qrcon”> [LT]h5> ‘.$iconstr.’ [LT]/h5> [LT]div class=”title”>微信扫码支付 ‘.$order_price.’ 元[LT]/div> [LT]div align=”center” class=”qrcode”> [LT]img src=”‘.$pay_qrcode_url.'”/> [LT]/div> [LT]div class=”bottom weixinpay”> 请使用微信扫一扫支付[LT]br>提示:若扫码支付失败,请重试[LT]br>或添加站长微信:1256069585 办理[LT]/br> [LT]/div> [LT]/div>’; echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘1’, ‘msg’ => $html_str, ‘img’ => $pay_qrcode_url, ‘num’ => $order_trade_no)); exit; } catch (Exception $e) { echo “errcode:{$e->getCode()},errmsg:{$e->getMessage()}”;exit; //TODO:处理支付调用异常的情况 } exit; } //码支付 codepay 微信 7 8支付宝 if ($pay_type == 7 || $pay_type == 8) { // 获取后台支付配置 $codepayConfig = _cao(‘codepay’); // 添加订单 ShopOrder if (!$ShopOrder->add($uid, $order_trade_no, $order_type, $order_price, $pay_type)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘订单创建失败’));exit; } //判断吗支付支付方式 switch ($pay_type) { case ‘7’: $paymethod = 1; // 支付宝 break; case ‘8’: $paymethod = 3; // 微信 break; } $params = array( “id” => $codepayConfig[‘mzf_appid’], “token” => $codepayConfig[‘mzf_token’], “pay_id” => $order_trade_no, //唯一标识 “type” => $paymethod,//1支付宝支付 3微信支付 2QQ钱包 “price” => $order_price,//金额 “param” => “rimini”,//自定义参数 “notify_url”=>get_template_directory_uri() . ‘/shop/codepay/notify.php’,//通知地址 ); //构造需要传递的参数 // 请求支付数据 $query = ‘id=’.$params[‘id’].’&token=’.$params[‘token’].’&price=’.$params[‘price’].’&pay_id=’.$params[‘pay_id’].’&type=’.$params[‘type’].’&notify_url=’.$params[‘notify_url’].’&page=4′; //创建订单所需的参数 $urls = ‘https://api.xiuxiu888.com/creat_order/creat_order?’.trim($query); //支付页面 $result = get_url_contents($urls); $resultData = json_decode($result,true); if ($resultData && $resultData[‘status’] == 0) { if ($paymethod == 3) { $iconstr = ‘[LT]img src=”‘.get_template_directory_uri()%20.%20’/assets/icons/weixin.png” class=”qr-pay”>’; $html_str = ‘[LT]div class=”qrcon”> [LT]h5> ‘.$iconstr.’ [LT]/h5> [LT]div class=”title”>微信扫码支付 ‘.$resultData[‘money’].’ 元[LT]/div> [LT]div align=”center” class=”qrcode”> [LT]img src=”‘.$resultData[‘qrcode’].'”/> [LT]/div> [LT]div class=”bottom weixinpay”>请使用微信扫一扫[LT]/br>[LT]b style=”font-size: 12px;color: #f10;”>请在五分钟内支付指定金额[LT]/b>[LT]/br>[LT]b style=” font-size: 12px; “>手机用户可保存上方二维码到手机中[LT]/b>[LT]/br>[LT]b style=” font-size: 12px; “>在微信扫一扫中选择“相册”即可[LT]/b> [LT]/div> [LT]/div>’; echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘1’, ‘msg’ => $html_str, ‘img’ => $resultData[‘qrcode’], ‘num’ => $order_trade_no)); exit; }else{ $iconstr = ‘[LT]img src=”‘.get_template_directory_uri()%20.%20’/assets/icons/alipay.png” class=”qr-pay”>’; $html_str = ‘[LT]div class=”qrcon”> [LT]h5> ‘.$iconstr.’ [LT]/h5> [LT]div class=”title”>支付宝扫码支付 ‘.$resultData[‘money’].’ 元[LT]/div> [LT]div align=”center” class=”qrcode”> [LT]img src=”‘.$resultData[‘qrcode’].'”/> [LT]/div> [LT]div class=”bottom alipay”> 请使用支付宝扫一扫[LT]br>[LT]b style=”font-size: 12px;color: #f10;”>请在五分钟内支付指定金额[LT]/b>[LT]/br>[LT]b style=” font-size: 12px; “>手机用户可保存上方二维码到手机中[LT]/b>[LT]/br>[LT]b style=” font-size: 12px; “>在支付宝扫一扫中选择“相册”即可[LT]/b> [LT]/div> [LT]/div>’; echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘1’, ‘msg’ => $html_str , ‘img’ => $resultData[‘qrcode’], ‘num’ => $order_trade_no)); exit; } }else{ echo json_encode(array(‘status’ => ‘0’, ‘msg’ => $resultData[‘msg’]));exit; } } } add_action(‘wp_ajax_charge_pay’, ‘charge_pay’); add_action(‘wp_ajax_nopriv_charge_pay’, ‘charge_pay’); /** * [go_post_pay 支付模式购买文章] * @Author Dadong2g * @DateTime 2020-01-15T11:41:26+0800 * @return [type] [description] */ function go_post_pay() { header(‘Content-type:application/json; Charset=utf-8’); $ip = (isset($_SERVER[‘REMOTE_ADDR’])) ? $_SERVER[‘REMOTE_ADDR’] : ‘127.0.0.1’; //客户端IP global $current_user; $uid = (is_user_logged_in()) ? $current_user->ID : 0 ; if ($uid>0 && !_cao(‘is_online_pay_status’,true)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘登录用户仅限请使用余额支付’));exit; } // isLoginCheck(); //检测登录 $nonce = !empty($_POST[‘nonce’]) ? $_POST[‘nonce’] : null; $post_id = !empty($_POST[‘post_id’]) ? (int)$_POST[‘post_id’] : 0; // 1支付宝官方;2微信官方 ;3 其他 ;4 PAYJS ;5 讯虎微信 ;6 讯虎支付宝 ;7 吗支付支付宝 ;8 吗支付微信 $pay_type = !empty($_POST[‘pay_type’]) ? (int) $_POST[‘pay_type’] : null; if ($nonce && !wp_verify_nonce($nonce, ‘caopay-‘ . $post_id)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘非法请求’));exit; } if ($post_id [LT]= 0) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘购买ID参数错误’));exit; } // 实例化订单 $ShopOrder = new ShopOrder(); $CaoUser = new CaoUser($uid); $PostPay = new PostPay($uid, $post_id); if (get_post_meta($post_id, ‘cao_close_novip_pay’, true) && !$CaoUser->vip_status()) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘该资源为会员专属资源,普通用户无购买权限!’));exit; } /////////商品属性START/////// $charge_rate = (int) _cao(‘site_change_rate’); //网站比例 //获取资源文章价格等信息 $post_price = $_post_price = get_post_meta($post_id, ‘cao_price’, true); $post_price = ($post_price) ? $post_price : ‘0’ ; // 计算价格 验证会员折扣权限 $post_vip_rate = get_post_meta($post_id, ‘cao_vip_rate’, true); $cao_is_boosvip = get_post_meta($post_id, ‘cao_is_boosvip’, true); if ($cao_is_boosvip && is_boosvip_status($uid)) { $post_price = 0; } if (_cao(‘is_online_pay_reta’,true)) { $vip_status = $CaoUser->vip_status(); $order_vip_rate = ($vip_status) ? $post_vip_rate : 1 ; // 折扣信息 if ($order_vip_rate == 0) { $post_price = 0; } elseif ($order_vip_rate == 1) { $post_price = $post_price; } elseif ($order_vip_rate > 0 && $order_vip_rate [LT] 1) { $post_price = sprintf(‘%0.2f’, $post_price*$order_vip_rate ); }else{ $post_price = $post_price; } }else{ $order_vip_rate = 1 ; $post_price = $post_price; } $order_price = sprintf(‘%0.2f’, $post_price / $charge_rate); // 订单价格 换算人民币,保留两位小数点 $order_trade_no = date(“ymdhis”) . mt_rand(100, 999) . mt_rand(100, 999) . mt_rand(100, 999); // 订单号 if (_cao(‘is_ripro_diy_shop_name’)) { $order_name = _cao(‘ripro_diy_shop_name_pay’); //自定义订单名称 }else{ $order_name = get_bloginfo(‘name’) . ‘-资源购买’; //订单名称 } $order_type = ‘other’; //类型 购买 其他 $post_vid = (int)$_POST[‘post_vid’]; if (!isset($post_vid) && $post_id==cao_get_page_by_slug(‘user’)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘请选择开通套餐’)); exit; } //start if (isset($post_vid) && $post_id==cao_get_page_by_slug(‘user’)) { # 获取后台价格设置 $vip_pay_setting = _cao(‘vip-pay-setting’); $payInfo = []; foreach ($vip_pay_setting as $key => $item) { if ($key == $post_vid) { $payInfo = $item; break; } } if (empty($payInfo)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘商城设置会员组设置不完善’)); exit; } $post_price = $payInfo[‘price’]; //积分价格 $pay_daynum = $payInfo[‘daynum’]; //开通天数 $order_price = sprintf(‘%0.2f’, $post_price / $charge_rate); // 订单价格 换算人民币,保留两位小数点 if ($pay_daynum==9999) { $order_name = get_bloginfo(‘name’) . ‘-开通永久’._cao(‘site_vip_name’); //订单名称 }else{ $order_name = get_bloginfo(‘name’) . ‘-开通’._cao(‘site_vip_name’).’【’.$pay_daynum.’天】’; //订单名称 } $_post_price = $post_price; } // end if ($post_price [LT]= 0) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘免费或’._cao(‘site_vip_name’).’免费资源仅限余额支付’));exit; } //写入本地文章购买记录 if (!$PostPay->add($_post_price, $order_vip_rate,$order_trade_no,$pay_type)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘添加订单异常’));exit; } /////////商品属性END///////// // 判断支付方式 1 支付宝 START if ($pay_type == 1) { // 获取后台支付宝配置 $aliPayConfig = _cao(‘alipay’); // 判断是否开启手机版跳转 if (wp_is_mobile() && $aliPayConfig[‘is_mobile’]) { // 添加订单 ShopOrder if (!$ShopOrder->add($uid, $order_trade_no, $order_type, $order_price, $pay_type)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘订单创建失败’));exit; } // 支付宝公共配置 $params = new YurunPaySDKAlipayParamsPublicParams; $params->appID = $aliPayConfig[‘pid’]; $params->md5Key = $aliPayConfig[‘md5Key’]; // SDK实例化,传入公共配置 $pay = new YurunPaySDKAlipaySDK($params); // 支付接口 $request = new YurunPaySDKAlipayParamsWapPayRequest; $request->notify_url = get_template_directory_uri() . ‘/shop/alipay/notify.php’; $request->return_url = get_template_directory_uri() . ‘/shop/alipay/return.php’; // 支付后跳转返回地址 $request->businessParams->seller_id = $aliPayConfig[‘pid’]; // 卖家支付宝用户号 $request->businessParams->out_trade_no = $order_trade_no; // 商户订单号 $request->businessParams->total_fee = $order_price; // 价格 $request->businessParams->subject = $order_name; // 商品标题 $request->businessParams->show_url = get_permalink($post_id); // 用户付款中途退出返回商户网站的地址。 $payurl = $pay->redirectExecuteUrl($request); $_SESSION[‘ali_session_order_trade_no’] = $order_trade_no; // type 1 = 扫码支付 2 跳转支付 echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘2’, ‘rurl’ => $payurl, ‘qrcode’ => ”, ‘msg’ => $order_trade_no)); exit; } elseif (!$aliPayConfig[‘is_pcqr’]) { // 支付宝-电脑网站支付 // 添加订单 ShopOrder if (!$ShopOrder->add($uid, $order_trade_no, $order_type, $order_price, $pay_type)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘订单创建失败’));exit; } // 支付宝公共配置 $params = new YurunPaySDKAlipayParamsPublicParams; $params->appID = $aliPayConfig[‘pid’]; $params->md5Key = $aliPayConfig[‘md5Key’]; // SDK实例化,传入公共配置 $pay = new YurunPaySDKAlipaySDK($params); // 支付接口 $request = new YurunPaySDKAlipayParamsPayRequest; $request->notify_url = get_template_directory_uri() . ‘/shop/alipay/notify.php’; $request->return_url = get_template_directory_uri() . ‘/shop/alipay/return.php’; // 支付后跳转返回地址 $request->businessParams->seller_id = $aliPayConfig[‘pid’]; // 卖家支付宝用户号 $request->businessParams->out_trade_no = $order_trade_no; // 商户订单号 $request->businessParams->total_fee = $order_price; // 价格 $request->businessParams->subject = $order_name; // 商品标题 // 跳转到支付宝页面 $payurl = $pay->redirectExecuteUrl($request); // var_dump($payurl); // type 1 = 扫码支付 2 跳转支付 echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘2’, ‘rurl’ => $payurl, ‘qrcode’ => ”, ‘msg’ => $order_trade_no)); exit; } else { // 应用模式公共配置-当面付 // 添加订单 ShopOrder if (!$ShopOrder->add($uid, $order_trade_no, $order_type, $order_price, $pay_type)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘订单创建失败’));exit; } // 更换公共配置文件 $params = new YurunPaySDKAlipayAppParamsPublicParams; $params->appID = $aliPayConfig[‘appid’]; $params->appPrivateKey = $aliPayConfig[‘privateKey’]; $params->appPublicKey = $aliPayConfig[‘publicKey’]; // SDK实例化,传入公共配置 $pay = new YurunPaySDKAlipayAppSDK($params); // 支付接口 $request = new YurunPaySDKAlipayAppFTFParamsQRRequest; $request->notify_url = get_template_directory_uri() . ‘/shop/alipay/notify2.php’; // 支付后通知地址 $request->businessParams->out_trade_no = $order_trade_no; // 商户订单号 $request->businessParams->total_amount = $order_price; // 价格 $request->businessParams->subject = $order_name; // 商品标题 // 调用接口 try{ $data = $pay->execute($request); } catch(Exception $e){ var_dump($pay->response->body()); } // QR内容 $qrimg = getQrcode($data[‘alipay_trade_precreate_response’][‘qr_code’]); $iconstr = ‘[LT]img src=”‘.get_template_directory_uri()%20.%20’/assets/icons/alipay.png” class=”qr-pay”>’; $html_str = ‘[LT]div class=”qrcon”> [LT]h5> ‘.$iconstr.’ [LT]/h5> [LT]div class=”title”>支付宝扫码支付 ‘.$order_price.’ 元[LT]/div> [LT]div align=”center” class=”qrcode”> [LT]img src=”‘.$qrimg.'”/> [LT]/div> [LT]div class=”bottom alipay”> 请使用支付宝扫一扫支付[LT]br>提示:若扫码支付失败,请重试[LT]br>或添加站长微信:1256069585 办理[LT]/br> [LT]/div> [LT]/div>’; echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘1’, ‘msg’ => $html_str, ‘img’ => $qrimg, ‘num’ => $order_trade_no)); exit; } } //END ALIPAY // 2 微信 if ($pay_type == 2) { // 获取后台支付配置 $wxPayConfig = _cao(‘weixinpay’); // 公共配置 $params = new YurunPaySDKWeixinParamsPublicParams; $params->appID = $wxPayConfig[‘appid’]; $params->mch_id = $wxPayConfig[‘mch_id’]; $params->key = $wxPayConfig[‘key’]; // SDK实例化,传入公共配置 $pay = new YurunPaySDKWeixinSDK($params); $the_openid = get_user_meta($uid, ‘open_mpweixin_openid’, true); // 判断是否开启手机版跳转 //微信当前免登陆h5跳转有问题 免登陆下不允许h5支付 if (wp_is_mobile() && $wxPayConfig[‘is_mobile’] && !is_weixin_view()) { // 添加订单 ShopOrder if (!$ShopOrder->add($uid, $order_trade_no, $order_type, $order_price, $pay_type)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘订单创建失败’));exit; } // 支付接口H5 $request = new YurunPaySDKWeixinH5ParamsPayRequest; $request->body = $order_name; // 商品描述 $request->out_trade_no = $order_trade_no; // 订单号 $request->total_fee = $order_price*100; // 订单总金额,单位为:分 $request->spbill_create_ip = $ip; // 客户端ip,必须传正确的用户ip,否则会报错 $request->notify_url = get_template_directory_uri() . ‘/shop/weixin/notify.php’; // 异步通知地址 $request->scene_info = new YurunPaySDKWeixinH5ParamsSceneInfo; $request->scene_info->type = ‘Wap’; // 可选值:IOS、Android、Wap // 下面参数根据type不同而不同 $request->scene_info->wap_url = get_template_directory_uri() . ‘/shop/weixin/return.php’; $request->scene_info->wap_name = get_bloginfo(‘name’); // 调用接口 $result = $pay->execute($request); if($pay->checkResult()){ $_SESSION[‘wx_session_order_trade_no’] = $order_trade_no; echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘2’, ‘rurl’ => $result[‘mweb_url’], ‘qrcode’ => ‘h5’, ‘num’ => $order_trade_no)); exit; }else{ $error_msg = $pay->getErrorCode() . ‘:’ . $pay->getError(); echo json_encode(array(‘status’ => ‘0’, ‘msg’ => $error_msg)); exit; } }elseif (_cao(‘is_oauth_mpweixin’) && $wxPayConfig[‘is_jsapi’] && is_weixin_view() && is_user_logged_in() && !empty($the_openid)) { // 添加订单 ShopOrder if (!$ShopOrder->add($uid, $order_trade_no, $order_type, $order_price, $pay_type)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘订单创建失败’));exit; } # JSAPI 模式 $request = new YurunPaySDKWeixinJSAPIParamsPayRequest; $request->body = $order_name; // 商品描述 $request->out_trade_no = $order_trade_no; // 订单号 $request->total_fee = $order_price*100; // 订单总金额,单位为:分 $request->spbill_create_ip = $ip; // 客户端ip $request->notify_url = get_template_directory_uri() . ‘/shop/weixin/notify.php’; // 异步通知地址 $request->openid = $the_openid; // 必须设置openid // 调用接口 $result = $pay->execute($request); if($pay->checkResult()) { $request = new YurunPaySDKWeixinJSAPIParamsJSParamsRequest; $request->prepay_id = $result[‘prepay_id’]; $jsapiParams = $pay->execute($request); // 最后需要将数据传给js,使用WeixinJSBridge进行支付 echo json_encode(array(‘status’ => ‘1’, ‘type’ => ‘3’, ‘msg’ => $jsapiParams, ‘img’ => ”, ‘num’ => $order_trade_no));exit; }else{ echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘未绑定公众号登录或网络错误’));exit; } } else { // PC使用当面付返回二维码 // 添加订单 ShopOrder if (!$ShopOrder->add($uid, $order_trade_no, $order_type, $order_price, $pay_type)) { echo json_encode(array(‘status’ => ‘0’, ‘msg’ => ‘订单创建失败’));exit; } // 支付接口 PC扫码 $request = new YurunPaySDKWeixinNativeParamsPayRequest; $request->body = $order_name; // 商品描述 $request->out_trade_no = $order_trade_no; // 订单号 $request->total_fee = $order_price*100; // 订单总金额,单位为:分 $request->spbill_create_ip = $ip; // 客户端ip $request->notify_url = get_template_directory_uri() . ‘/shop/weixin/notify.php’; // 异步通知地址 // 调用接口 $result = $pay->execute($request); $shortUrl = $result[‘code_url’]; if (is_array($result) && $shortUrl) { // 获取成功 返回QR内容 $qrimg = getQrcode($shortUrl); $iconstr = ‘[LT]img src=”‘.get_template_directory_uri()%20.%20’/assets/icons/weixin.png” class=”qr-pay”>’; $html_str = ‘[LT]div class=”qrcon”> [LT]h5> ‘.$iconstr.’ [LT]/h5> [LT]div class=”title”>微信扫码支付 ‘.$order_price.’ 元[LT]/div> [LT]div align=”center” class=”qrcode”> [LT]img src=”‘.$qrimg.'”/> [LT]/div> [LT]div class=”bottom weixinpay”> 请使用微信扫一扫支付[LT]br>提示:若扫码支付失败,请重试[LT]br>或添加站长微信:1256069585
您身边的影视解说专家,做最全最好的影视解说文案网!
678解说文案网 » CHX60000