Пример #1
0
 /**
  * 微信支付
  * @param  string $re_openid 用户openid
  * @param  [type] $db        [description]
  * @param  array  $payarr    微信接口的红包信息
  * @return [type]            [description]
  */
 public function pay($re_openid = '', $db = null, $payarr)
 {
     //        echo 'hongbao';die;
     include_once 'WxHongBaoHelper.php';
     $commonUtil = new CommonUtil();
     $wxHongBaoHelper = new WxHongBaoHelper();
     $wxHongBaoHelper->setParameter("nonce_str", $this->great_rand());
     //随机字符串,丌长于 32 位
     $wxHongBaoHelper->setParameter("mch_billno", $this->app_mchid . date('YmdHis') . rand(1000, 9999));
     //订单号
     $wxHongBaoHelper->setParameter("mch_id", $this->app_mchid);
     //商户号
     $wxHongBaoHelper->setParameter("wxappid", $this->app_id);
     $wxHongBaoHelper->setParameter("nick_name", '红包');
     //提供方名称
     $wxHongBaoHelper->setParameter("send_name", '红包');
     //红包发送者名称
     $wxHongBaoHelper->setParameter("re_openid", $re_openid);
     //相对于医脉互通的openid
     $wxHongBaoHelper->setParameter("total_amount", $payarr['total_amount']);
     //付款金额,单位分
     $wxHongBaoHelper->setParameter("min_value", $payarr['min_value']);
     //最小红包金额,单位分
     $wxHongBaoHelper->setParameter("max_value", $payarr['max_value']);
     //最大红包金额,单位分
     $wxHongBaoHelper->setParameter("total_num", 1);
     //红包収放总人数
     $wxHongBaoHelper->setParameter("wishing", '恭喜发财');
     //红包祝福诧
     $client_ip = gethostbyname($_ENV['COMPUTERNAME']);
     //        echo $client_ip;die;
     //        1246041702201506060917141106
     $wxHongBaoHelper->setParameter("client_ip", $client_ip);
     //调用接口的机器 Ip 地址
     $wxHongBaoHelper->setParameter("act_name", '红包活动');
     //活劢名称
     $wxHongBaoHelper->setParameter("remark", '快来抢!');
     //备注信息
     $postXml = $wxHongBaoHelper->create_hongbao_xml();
     //        echo $postXml;die;
     $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
     $responseXml = $wxHongBaoHelper->curl_post_ssl($url, $postXml);
     // echo $responseXml;die;
     $responseObj = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
     // echo 'wx return code is: ' . $responseObj->return_code;die;
     return $responseObj->return_code;
     // return;
 }
Пример #2
0
require_once 'pay/WxXianjinHelper.php';
$sysconfig = mysql_fetch_array(mysql_query("select cappid,cappsecret,cappkey,cmchid,cyongjin from " . DBQIAN . "sys_config limit 1"));
$hongbaorow = mysql_fetch_array(mysql_query("select htotalmoney,hminmoney,hmaxmoney,hdesc from " . DBQIAN . "xianjin_set limit 1"));
define('ROOT_PATH', dirname(__FILE__));
define('DS', DIRECTORY_SEPARATOR);
define('APPID', $sysconfig['cappid']);
define('APPSECRET', $sysconfig['cappsecret']);
define('PARTNERKEY', $sysconfig['cappkey']);
//密钥
define('MCHID', $sysconfig['cmchid']);
//商户号
define("TOTALMONEY", $hongbaorow['htotalmoney']);
//发送总金额,分为单位
$tools = new tools();
$commonUtil = new CommonUtil();
$wxHongBaoHelper = new WxHongBaoHelper();
//状态码说明,0正常 1ucode错误 2领取过了 3领取成功返回领取金额 4系统错误
$actioncode = 0;
$ucode = $_POST['ucode'];
$uwxcode = $_POST['uwxcode'];
if ($ucode == '' || $uwxcode == '') {
    $actioncode = 1;
}
//判断是否领过了
$ulingnum = mysql_num_rows(mysql_query("select * from " . DBQIAN . "user_xianjin where ucode='{$ucode}' and uwxcode='{$uwxcode}' and xtype=1 limit 1"));
if ($ulingnum > 0 && $actioncode == 0) {
    $actioncode = 2;
}
//计算大小
if ($actioncode == 0) {
    $thismoney = intval($hongbaorow['hminmoney']);