public static function createJsBizPackage($openid, $totalFee, $outTradeNo, $orderName, $notifyUrl, $timestamp)
{
$config = self::getConfig();
$unified = array('appid' => $config['appid'], 'attach' => '支付', 'body' => $orderName, 'mch_id' => $config['mch_id'], 'nonce_str' => self::createNonceStr(), 'notify_url' => $notifyUrl, 'openid' => $openid, 'out_trade_no' => $outTradeNo, 'spbill_create_ip' => '127.0.0.1', 'total_fee' => sprintf('%.0f', self::calc($totalFee, 100, '*', 2)), 'trade_type' => 'JSAPI');
$unified['sign'] = self::getSign($unified, $config['key']);
$responseXml = self::curlPost('https://api.mch.weixin.qq.com/pay/unifiedorder', self::arrayToXml($unified));
/*
<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
<appid><![CDATA[wx00e5904efec77699]]></appid>
<mch_id><![CDATA[1220647301]]></mch_id>
<nonce_str><![CDATA[1LHBROsdmqfXoWQR]]></nonce_str>
<sign><![CDATA[ACA7BC8A9164D1FBED06C7DFC13EC839]]></sign>
<result_code><![CDATA[SUCCESS]]></result_code>
<prepay_id><![CDATA[wx2015032016590503f1bcd9c30421762652]]></prepay_id>
<trade_type><![CDATA[JSAPI]]></trade_type>
</xml>
*/
$unifiedOrder = @simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
//Log::info($responseXml);
if ($unifiedOrder === false) {
die('parse xml error');
}
if ("{$unifiedOrder->return_code}" !== 'SUCCESS') {
die($unifiedOrder->return_msg);
}
if ("{$unifiedOrder->result_code}" !== 'SUCCESS') {
die($unifiedOrder->err_code);
/*
NOAUTH 商户无此接口权限
NOTENOUGH 余额不足
ORDERPAID 商户订单已支付
ORDERCLOSED 订单已关闭
SYSTEMERROR 系统错误
APPID_NOT_EXIST APPID不存在
MCHID_NOT_EXIST MCHID不存在
APPID_MCHID_NOT_MATCH appid和mch_id不匹配
LACK_PARAMS 缺少参数
OUT_TRADE_NO_USED 商户订单号重复
SIGNERROR 签名错误
XML_FORMAT_ERROR XML格式错误
REQUIRE_POST_METHOD 请使用post方法
POST_DATA_EMPTY post数据为空
NOT_UTF8 编码格式错误
*/
}
//$unifiedOrder->trade_type 交易类型 调用接口提交的交易类型,取值如下:JSAPI,NATIVE,APP
//$unifiedOrder->prepay_id 预支付交易会话标识 微信生成的预支付回话标识,用于后续接口调用中使用,该值有效期为2小时
//$unifiedOrder->code_url 二维码链接 trade_type为NATIVE是有返回,可将该参数值生成二维码展示出来进行扫码支付
$arr = array("appId" => $config['appid'], "timeStamp" => $timestamp, "nonceStr" => self::createNonceStr(), "package" => "prepay_id=" . $unifiedOrder->prepay_id, "signType" => 'MD5');
$arr['paySign'] = self::getSign($arr, $config['key']);
return $arr;
}