作者 潘浩文
1 个管道 的构建 通过 耗费 0 秒

订单渲染

... ... @@ -232,5 +232,7 @@ $configs = [
'cmf_default_theme' => 'simpleboot3',
'cmf_admin_theme_path' => 'themes/',
'cmf_admin_default_theme' => 'admin_simpleboot3',
'WX_APPID'=>'wx6ac38fa39586acfd',
'WX_APP_SECRET'=>'b89205a0b3f6daaaaf4cfbdc7029293c',
];
return array_merge($configs, $runtimeConfig,$wechatConfig);
\ No newline at end of file
... ...
... ... @@ -139,17 +139,41 @@ class IndexController extends WeChatBaseController
return $this->fetch(':light_order');
}
public function listOrderPost()
public function pay()
{
$options = [
'app_id' => config('wechat_config.app_id'),
'secret' => config('wechat_config.secret'),
'payment' => config('wechat_config.payment'),
];
$app = new Application($options);
$js = $app->js;
$jss = $js->config(['chooseImage', 'uploadImage', 'previewImage'], $debug = false, $beta = false, $json = true);
$this->assign('js', $jss); }
$re=$this->checkLogin();
$param = $this->request->param();
$data['avatar'] = $this->upload_wx_pic_mul($param['media']);
$param['update_time']=time();
$data=Db::name('goods_order')->where('id',$id)->update($param);
}
public function upload_wx_pic_mul()
{
require_once VENDOR_PATH . "jssdk/jssdk.php";
$jssdk = new \JSSDK(Config('WX_APPID'), Config('WX_APP_SECRET'));
$access_token = $jssdk->getAccessToken();
$img_str = $this->request->param('media');
$file = $this->getmedia($access_token,$img_str, date('Ymd'));
return $file;
}
public function getmedia($access_token, $media_id, $foldername)
{
$url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" . $access_token . "&media_id=" . $media_id;
if (!file_exists("./upload/" . $foldername)) {
mkdir("./upload/" . $foldername, 0777, true);
}
$file_name = date('YmdHis') . rand(1000, 9999) . '.jpg';
$targetName = './upload/' . $foldername . '/' . $file_name;
$saveName = $foldername . '/' . $file_name;
$ch = curl_init($url); // 初始化
$fp = fopen($targetName, 'wb'); // 打开写入
curl_setopt($ch, CURLOPT_FILE, $fp); // 设置输出文件的位置,值是一个资源类型
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
return $saveName;
}
}
... ...
<?php exit();?>{"access_token":"14_inPgNqVQwEnC-OI-U9eqjHElTubcal4Vem7Xej5yIhMRJph17RTIoHGsu6BqCAL8v6SmIsYX2F_TKxHZ-k2X0oketUQOCiABVai2pJFDmMjoMDceYZfR3mTvDV0op5FjIxun89gYvgMPljAXXBNcAFARVH","expire_time":1539683880}
\ No newline at end of file
... ...
<?php exit();?>
{"jsapi_ticket":"","expire_time":0}
... ...
<?php
class JSSDK {
private $appId;
private $appSecret;
public function __construct($appId, $appSecret) {
$this->appId = $appId;
$this->appSecret = $appSecret;
}
public function getSignPackage() {
$jsapiTicket = $this->getJsApiTicket();
// 注意 URL 一定要动态获取,不能 hardcode.
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$timestamp = time();
$nonceStr = $this->createNonceStr();
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
$signature = sha1($string);
$signPackage = array(
"appId" => $this->appId,
"nonceStr" => $nonceStr,
"timestamp" => $timestamp,
"url" => $url,
"signature" => $signature,
"rawString" => $string
);
return $signPackage;
}
public function createNonceStr($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
public function getJsApiTicket() {
// jsapi_ticket 应该全局存储与更新,以下代码以写入到文件中做示例
$data = json_decode($this->get_php_file(VENDOR_PATH."jssdk/jsapi_ticket.php"));
if ($data->expire_time < time()) {
$accessToken = $this->getAccessToken();
// 如果是企业号用以下 URL 获取 ticket
// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
$res = json_decode($this->httpGet($url));
$ticket = $res->ticket;
if ($ticket) {
$data->expire_time = time() + 7000;
$data->jsapi_ticket = $ticket;
$this->set_php_file(VENDOR_PATH."jssdk/jsapi_ticket.php", json_encode($data));
}
} else {
$ticket = $data->jsapi_ticket;
}
return $ticket;
}
public function getAccessToken() {
// access_token 应该全局存储与更新,以下代码以写入到文件中做示例
$data = json_decode($this->get_php_file(VENDOR_PATH."jssdk/access_token.php"));
if ($data->expire_time < time()) {
// 如果是企业号用以下URL获取access_token
// $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
$res = json_decode($this->httpGet($url));
$access_token = $res->access_token;
if ($access_token) {
$data->expire_time = time() + 7000;
$data->access_token = $access_token;
$this->set_php_file(VENDOR_PATH."jssdk/access_token.php", json_encode($data));
}
} else {
$access_token = $data->access_token;
}
return $access_token;
}
public function httpGet($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
// 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
// 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
public function get_php_file($filename) {
return trim(substr(file_get_contents($filename), 15));
}
public function set_php_file($filename, $content) {
$fp = fopen($filename, "w");
fwrite($fp, "<?php exit();?>" . $content);
fclose($fp);
}
}
... ...