UserModel.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Model;
  15. class UserModel{
  16. public function get_member_count($where='')
  17. {
  18. $total = M('lionfish_comshop_member')->where("1 ".$where)->count();
  19. return $total;
  20. }
  21. //------------------------------------------------begin
  22. public function delete_use_auto_template()
  23. {
  24. @set_time_limit(0);
  25. $config_data = array();
  26. $weixin_config = array();
  27. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  28. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  29. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  30. $re_access_token = $jssdk->getweAccessToken();
  31. $send_url ="https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token={$re_access_token}";
  32. $data = array();
  33. $data['offset'] = 0;
  34. $data['count'] = 20;
  35. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  36. $result = json_decode($result_json, true);
  37. $del_title_arr = array('申请成功提醒','退款成功通知','订单支付成功通知','订单发货提醒','核销成功通知','提现到账通知');
  38. $del_template_arr = array();
  39. if($result['errcode'] == 0)
  40. {
  41. foreach( $result['list'] as $val )
  42. {
  43. if( in_array($val['title'], $del_title_arr) )
  44. {
  45. $del_template_arr[] = $val['template_id'];
  46. }
  47. }
  48. }
  49. if( !empty($del_template_arr) )
  50. {
  51. foreach($del_template_arr as $vv)
  52. {
  53. $send_url ="https://api.weixin.qq.com/cgi-bin/wxopen/template/del?access_token={$re_access_token}";
  54. $data = array();
  55. $data['template_id'] = $vv;
  56. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  57. }
  58. }
  59. //https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN
  60. }
  61. public function mange_template_auto()
  62. {
  63. $this->delete_use_auto_template();
  64. @set_time_limit(0);
  65. $config_data = array();
  66. $weixin_config = array();
  67. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  68. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  69. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  70. $re_access_token = $jssdk->getweAccessToken();
  71. $send_url ="https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token={$re_access_token}";
  72. //-----------------团长申请成功发送通知------------------------
  73. $data = array();
  74. $data['id'] = 'AT0197';
  75. $data['keyword_id_list'] = array(1,13,3,6,77,44,50);
  76. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  77. $result = json_decode($result_json, true);
  78. if($result['errcode'] == 0)
  79. {
  80. $config_data['weprogram_template_apply_community'] = $result['template_id'];
  81. }
  82. //------------------订单支付成功通知----------------------------
  83. $data = array();
  84. $data['id'] = 'AT0009';
  85. $data['keyword_id_list'] = array(1,13,10,11,20);
  86. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  87. $result = json_decode($result_json, true);
  88. if($result['errcode'] == 0)
  89. {
  90. $config_data['weprogram_template_pay_order'] = $result['template_id'];
  91. }
  92. //---------------------------------------------------------------
  93. //------------------订单发货提醒---------------------------------
  94. $data = array();
  95. $data['id'] = 'AT0007';
  96. $data['keyword_id_list'] = array(5,7,47,34,11);
  97. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  98. $result = json_decode($result_json, true);
  99. if($result['errcode'] == 0)
  100. {
  101. $config_data['weprogram_template_send_order'] = $result['template_id'];
  102. }
  103. //---------------------------------------------------------------
  104. //------------------核销成功通知---------------------------------
  105. $data = array();
  106. $data['id'] = 'AT0423';
  107. $data['keyword_id_list'] = array(5,2,6,3,9);
  108. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  109. $result = json_decode($result_json, true);
  110. if($result['errcode'] == 0)
  111. {
  112. $config_data['weprogram_template_hexiao_success'] = $result['template_id'];
  113. }
  114. //---------------------------------------------------------------
  115. //------------------退款成功通知---------------------------------
  116. $data = array();
  117. $data['id'] = 'AT0787';
  118. $data['keyword_id_list'] = array(8,13,14,17,7,18);
  119. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  120. $result = json_decode($result_json, true);
  121. if($result['errcode'] == 0)
  122. {
  123. $config_data['weprogram_template_refund_order'] = $result['template_id'];
  124. }
  125. //---------------------------------------------------------------
  126. //------------------提现到账通知---------------------------------
  127. $data = array();
  128. $data['id'] = 'AT0830';
  129. $data['keyword_id_list'] = array(5,3,1,6,8,11,2);
  130. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  131. $result = json_decode($result_json, true);
  132. if($result['errcode'] == 0)
  133. {
  134. $config_data['weprogram_template_apply_tixian'] = $result['template_id'];
  135. }
  136. //---------------------------------------------------------------
  137. //------------------拼团开团通知---------------------------------
  138. $data = array();
  139. $data['id'] = 'AT0541';
  140. $data['keyword_id_list'] = array(15,1,10,26,24);
  141. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  142. $result = json_decode($result_json, true);
  143. if($result['errcode'] == 0)
  144. {
  145. $config_data['weprogram_template_open_tuan'] = $result['template_id'];
  146. }
  147. //---------------------------------------------------------------
  148. //------------------参团通知---------------------------------
  149. $data = array();
  150. $data['id'] = 'AT0933';
  151. $data['keyword_id_list'] = array(3,18,27);
  152. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  153. $result = json_decode($result_json, true);
  154. if($result['errcode'] == 0)
  155. {
  156. $config_data['weprogram_template_take_tuan'] = $result['template_id'];
  157. }
  158. //------------------拼团成功通知---------------------------------
  159. $data = array();
  160. $data['id'] = 'AT0051';
  161. $data['keyword_id_list'] = array(13,6,12);
  162. $result_json = $this->sendhttps_post($send_url, json_encode($data));
  163. $result = json_decode($result_json, true);
  164. if($result['errcode'] == 0)
  165. {
  166. $config_data['weprogram_template_pin_tuansuccess'] = $result['template_id'];
  167. }
  168. //---------------------------------------------------------------
  169. D('Seller/Config')->update($config_data);
  170. //AT0197 申请时间 所在地 服务地址 姓名 手机号 申请状态 同意时间1
  171. }
  172. //-----------------------------------------------end
  173. //--------begin
  174. /**
  175. 更改会员余额
  176. **/
  177. public function sendMemberMoneyChange($member_id, $num, $changetype, $remark='')
  178. {
  179. $member_info = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' => $member_id) )->find();
  180. $account_money = $member_info['account_money'];
  181. $flow_data = array();
  182. $flow_data['member_id'] = $member_id;
  183. $flow_data['trans_id'] = '';
  184. //0,未支付,1已支付,3余额付款,4退款到余额,5后台充值 6 后台扣款
  185. //增加
  186. if($changetype == 0)
  187. {
  188. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = account_money+ ".$num ." where member_id=".$member_id;
  189. $flow_data['state'] = '5';
  190. }else if($changetype == 1)
  191. {
  192. //减少
  193. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = account_money - ".$num ." where member_id=".$member_id;
  194. $flow_data['state'] = '8';
  195. }else if($changetype == 2){
  196. //最终积分
  197. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = ".$num ." where member_id=".$member_id;
  198. if($account_money >= $num)
  199. {
  200. $flow_data['state'] = '8';
  201. $num = $account_money - $num;
  202. }else{
  203. $flow_data['state'] = '5';
  204. $num = $num - $account_money;
  205. }
  206. }
  207. else if( $changetype == 9 )
  208. {
  209. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = account_money+ ".$num ." where member_id=".$member_id;
  210. $flow_data['state'] = '9';
  211. }
  212. else if( $changetype == 10 )
  213. {
  214. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = account_money+ ".$num ." where member_id=".$member_id;
  215. $flow_data['state'] = '10';
  216. }else if( $changetype == 11 )
  217. {//拼团佣金
  218. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = account_money+ ".$num ." where member_id=".$member_id;
  219. $flow_data['state'] = '11';
  220. }else if( $changetype == 12 )
  221. {//配送佣金
  222. $account_money = $account_money + $num;
  223. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set account_money = ".$account_money ." where member_id=".$member_id;
  224. $flow_data['state'] = '12';
  225. }
  226. $flow_data['money'] = $num;
  227. $flow_data['remark'] = $remark;
  228. $flow_data['charge_time'] = time();
  229. $flow_data['add_time'] = time();
  230. M()->execute( $up_sql );
  231. $member_info2 = M('lionfish_comshop_member')->field('account_money')->where( array('member_id' => $member_id) )->find();
  232. $flow_data['operate_end_yuer'] = $member_info2['account_money'];
  233. M('lionfish_comshop_member_charge_flow')->add($flow_data);
  234. }
  235. /**
  236. 更新会员积分
  237. **/
  238. public function sendMemberPointChange($member_id,$num, $changetype ,$remark ='', $ch_type='system_add')
  239. {
  240. $member_info = M('lionfish_comshop_member')->field('score')->where( array('member_id' => $member_id) )->find();
  241. $member_score = $member_info['score'];
  242. $flow_data = array();
  243. $flow_data['member_id'] = $member_id;
  244. $flow_data['type'] = $ch_type;
  245. $flow_data['order_id'] = '0';
  246. //增加
  247. if($changetype == 0)
  248. {
  249. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set score = score+ ".$num ." where member_id=".$member_id;
  250. $flow_data['in_out'] = 'in';
  251. }else if($changetype == 1)
  252. {
  253. //减少
  254. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set score = score - ".$num ." where member_id=".$member_id;
  255. $flow_data['in_out'] = 'out';
  256. }else if($changetype == 2){
  257. //最终积分
  258. $up_sql = "update ".C('DB_PREFIX')."lionfish_comshop_member set score = ".$num ." where member_id=".$member_id;
  259. if($member_score >= $num)
  260. {
  261. $flow_data['in_out'] = 'out';
  262. $num = $member_score - $num;
  263. }else{
  264. $flow_data['in_out'] = 'in';
  265. $num = $num - $member_score;
  266. }
  267. }
  268. //after_operate_score
  269. $flow_data['score'] = $num;
  270. $flow_data['state'] = 1;
  271. $flow_data['remark'] = $remark;
  272. $flow_data['addtime'] = time();
  273. M()->execute( $up_sql );
  274. $info = M('lionfish_comshop_member')->field('score')->where( array('member_id' => $member_id ) )->find();
  275. $flow_data['after_operate_score'] = $info['score'];
  276. M('lionfish_comshop_member_integral_flow')->add($flow_data);
  277. }
  278. //--------end
  279. /**
  280. * [addTemplates (订阅消息)
  281. * @param [type] tid [模板标题id]
  282. * @param [type] kidList [模板关键词列表]
  283. * @param [type] sceneDesc [服务场景描述]
  284. */
  285. //订阅信息一键获取
  286. public function mange_subscribetemplate_auto()
  287. {
  288. $this->delete_use_auto_template();
  289. @set_time_limit(0);
  290. $config_data = array();
  291. $weixin_config = array();
  292. $weixin_config['appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  293. $weixin_config['appscert'] = D('Home/Front')->get_config_by_name('wepro_appsecret');
  294. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  295. $re_access_token = $jssdk->getweAccessToken($uniacid);
  296. //判断用户的小程序类目中,是否有咱们需要的小程序类目,如果没有,给他提示出来缺什么类目。
  297. $category_url = "https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token={$re_access_token}";
  298. $result_category =array();
  299. $result_category_json = $this->curl_category($category_url);
  300. $result_category = json_decode($result_category_json, true);
  301. // {"id":670,"name":"线下超市/便利店"},{"id":307,"name":"服装/鞋/箱包"}
  302. $name = array_column($result_category['data'], 'name');
  303. $found_supermarket = in_array("线下超市/便利店", $name);
  304. $found_clothing = in_array("服装/鞋/箱包", $name);
  305. if( empty($found_supermarket) && empty($found_clothing) ){
  306. if(empty($found_supermarket)){
  307. //show_json(0, array('message' => '请在微信公众平台添加 "线下超市/便利店" 类目') );
  308. show_json(0, array('message' => '请在微信公众平台添加商家自营--->服装/鞋/箱包 、 生活服务--->百货/线下超市/便利店') );
  309. die();
  310. }
  311. if(empty($found_clothing)){
  312. //show_json(0, array('message' => '请在微信公众平台添加 "服装/鞋/箱包" 类目' ) );
  313. show_json(0, array('message' => '请在微信公众平台添加商家自营--->服装/鞋/箱包 、 生活服务--->百货/线下超市/便利店' ) );
  314. die();
  315. }
  316. }else{
  317. //删除
  318. $del_url = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token={$re_access_token}";
  319. $send_url ="https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token={$re_access_token}";
  320. //https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=
  321. //------------------订单支付成功通知----------------------------
  322. $data = array();
  323. $data['tid'] = '1253';
  324. $data['kidList'] = array(1,2,3,4,7);
  325. $data['sceneDesc'] ='用户支付订单';
  326. //先删除再添加
  327. $arr = array();
  328. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pay_order');
  329. if(!empty($arr['priTmplId'])){
  330. $result_del_json = $this->curl_datas($del_url,$arr);
  331. $result_del = json_decode($result_del_json, true);
  332. }
  333. //$result_json = $this->curl_datas($send_url, json_encode($data));
  334. $result_json = $this->curl_datas($send_url,$data);
  335. $result = json_decode($result_json, true);
  336. if($result['errcode'] == 0)
  337. {
  338. $config_data['weprogram_subtemplate_pay_order'] = $result['priTmplId'];
  339. }
  340. //---------------------------------------------------------------
  341. //------------------订单发货提醒---------------------------------
  342. $data = array();
  343. $data['tid'] = '855';
  344. $data['kidList'] = array(1,2,3,6,9);
  345. $data['sceneDesc'] ='用户订单发货';
  346. //先删除再添加
  347. $arr = array();
  348. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_send_order');
  349. if(!empty($arr['priTmplId'])){
  350. $result_del_json = $this->curl_datas($del_url,$arr);
  351. $result_del = json_decode($result_del_json, true);
  352. }
  353. $result_json = $this->curl_datas($send_url,$data);
  354. $result = json_decode($result_json, true);
  355. if($result['errcode'] == 0)
  356. {
  357. $config_data['weprogram_subtemplate_send_order'] = $result['priTmplId'];
  358. }
  359. //---------------------------------------------------------------
  360. //------------------核销成功通知---------------------------------
  361. $data = array();
  362. $data['tid'] = '3116';
  363. $data['kidList'] = array(2,3,4);
  364. $data['sceneDesc'] ='商家核销';
  365. //先删除再添加
  366. $arr = array();
  367. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_hexiao_success');
  368. if(!empty($arr['priTmplId'])){
  369. $result_del_json = $this->curl_datas($del_url,$arr);
  370. $result_del = json_decode($result_del_json, true);
  371. }
  372. $result_json = $this->curl_datas($send_url,$data);
  373. $result = json_decode($result_json, true);
  374. if($result['errcode'] == 0)
  375. {
  376. $config_data['weprogram_subtemplate_hexiao_success'] = $result['priTmplId'];
  377. }
  378. //---------------------------------------------------------------
  379. /*------------------退款成功通知---------------------------------
  380. $data = array();
  381. $data['tid'] = 'AT0197';
  382. $data['kidList'] = array(1,13,3,6,77,44,50);
  383. $result_json = $this->curl_datas($send_url,$data);
  384. $result = json_decode($result_json, true);
  385. if($result['errcode'] == 0)
  386. {
  387. $config_data['weprogram_subtemplate_refund_order'] = $result['template_id'];
  388. }
  389. //--------------------------------------------------------------- */
  390. //-----------------团长申请成功发送通知------------------------
  391. $data = array();
  392. $data['tid'] = '3635';
  393. $data['kidList'] = array(1,2,3,4,5);
  394. $data['sceneDesc'] ='团长申请成功';
  395. //先删除再添加
  396. $arr = array();
  397. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_community');
  398. if(!empty($arr['priTmplId'])){
  399. $result_del_json = $this->curl_datas($del_url,$arr);
  400. $result_del = json_decode($result_del_json, true);
  401. }
  402. $result_json = $this->curl_datas($send_url,$data);
  403. $result = json_decode($result_json, true);
  404. if($result['errcode'] == 0)
  405. {
  406. $config_data['weprogram_subtemplate_apply_community'] = $result['priTmplId'];
  407. }
  408. //---------------------------------------------------------------
  409. //------------------拼团开团通知---------------------------------
  410. $data = array();
  411. $data['tid'] = '3185';
  412. $data['kidList'] = array(1,2,3,5);
  413. $data['sceneDesc'] ='团长开团';
  414. //先删除再添加
  415. $arr = array();
  416. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_open_tuan');
  417. if(!empty($arr['priTmplId'])){
  418. $result_del_json = $this->curl_datas($del_url,$arr);
  419. $result_del = json_decode($result_del_json, true);
  420. }
  421. $result_json = $this->curl_datas($send_url,$data);
  422. $result = json_decode($result_json, true);
  423. if($result['errcode'] == 0)
  424. {
  425. $config_data['weprogram_subtemplate_open_tuan'] = $result['priTmplId'];
  426. }
  427. //---------------------------------------------------------------
  428. //------------------参团通知-------------------------------------
  429. $data = array();
  430. $data['tid'] = '3653';
  431. $data['kidList'] = array(1,2,3);
  432. $data['sceneDesc'] ='团员参团';
  433. //先删除再添加
  434. $arr = array();
  435. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_take_tuan');
  436. if(!empty($arr['priTmplId'])){
  437. $result_del_json = $this->curl_datas($del_url,$arr);
  438. $result_del = json_decode($result_del_json, true);
  439. }
  440. $result_json = $this->curl_datas($send_url,$data);
  441. $result = json_decode($result_json, true);
  442. if($result['errcode'] == 0)
  443. {
  444. $config_data['weprogram_subtemplate_take_tuan'] = $result['priTmplId'];
  445. }
  446. //---------------------------------------------------------------
  447. //------------------拼团成功通知---------------------------------
  448. $data = array();
  449. $data['tid'] = '980';
  450. $data['kidList'] = array(1,3,7);
  451. $data['sceneDesc'] ='拼团成功';
  452. //先删除再添加
  453. $arr = array();
  454. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pin_tuansuccess');
  455. if(!empty($arr['priTmplId'])){
  456. $result_del_json = $this->curl_datas($del_url,$arr);
  457. $result_del = json_decode($result_del_json, true);
  458. }
  459. $result_json = $this->curl_datas($send_url,$data);
  460. $result = json_decode($result_json, true);
  461. if($result['errcode'] == 0)
  462. {
  463. $config_data['weprogram_subtemplate_pin_tuansuccess'] = $result['priTmplId'];
  464. }
  465. //---------------------------------------------------------------
  466. //------------------提现到账通知---------------------------------
  467. $data = array();
  468. $data['tid'] = '2001';
  469. $data['kidList'] = array(1,2,3,4);
  470. $data['sceneDesc'] ='供应商申请提现';
  471. //先删除再添加
  472. $arr = array();
  473. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_tixian');
  474. if(!empty($arr['priTmplId'])){
  475. $result_del_json = $this->curl_datas($del_url,$arr);
  476. $result_del = json_decode($result_del_json, true);
  477. }
  478. $result_json = $this->curl_datas($send_url,$data);
  479. $result = json_decode($result_json, true);
  480. if($result['errcode'] == 0)
  481. {
  482. $config_data['weprogram_subtemplate_apply_tixian'] = $result['priTmplId'];
  483. }
  484. //---------------------------------------------------------------
  485. //-----------------预售商品到货通知
  486. $data = array();
  487. $data['tid'] = '339';
  488. $data['kidList'] = array(2,3,7);
  489. $data['sceneDesc'] ='预定到货通知';
  490. //先删除再添加
  491. $arr = array();
  492. $arr['priTmplId'] = D('Home/Front')->get_config_by_name('weprogram_subtemplate_presale_ordercan_continuepay');
  493. if(!empty($arr['priTmplId'])){
  494. $result_del_json = $this->curl_datas($del_url,$arr);
  495. $result_del = json_decode($result_del_json, true);
  496. }
  497. $result_json = $this->curl_datas($send_url,$data);
  498. $result = json_decode($result_json, true);
  499. if($result['errcode'] == 0)
  500. {
  501. $config_data['weprogram_subtemplate_presale_ordercan_continuepay'] = $result['priTmplId'];
  502. }
  503. //---------------------------------------------------------------
  504. D('Seller/Config')->update($config_data);
  505. }
  506. }
  507. function curl_category($url)
  508. {
  509. $ch = curl_init();
  510. //取数据的地址
  511. curl_setopt($ch, CURLOPT_URL, $url);
  512. //传输为post
  513. if(defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
  514. curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  515. }
  516. //隐藏返回结果
  517. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  518. curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
  519. curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
  520. //执行
  521. $handles = curl_exec($ch);
  522. //断开
  523. curl_close($ch);
  524. return $handles;
  525. }
  526. /**
  527. 发送订阅小程序消息
  528. **/
  529. function send_subscript_msg( $template_data,$url,$pagepath,$to_openid,$template_id, $delay_time = 0 )
  530. {
  531. $weixin_config = array();
  532. $weixin_config['appid'] = D('Seller/Front')->get_config_by_name('wepro_appid');
  533. $weixin_config['appscert'] = D('Seller/Front')->get_config_by_name('wepro_appsecret');
  534. $siteroot = D('Seller/Front')->get_config_by_name('shop_domain');
  535. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  536. $re_access_token = $jssdk->getweAccessToken();
  537. $template = array(
  538. 'touser' => $to_openid,
  539. 'template_id' => $template_id,
  540. 'page' => $pagepath,
  541. 'data' => $template_data
  542. );
  543. if($delay_time > 0)
  544. sleep($delay_time);
  545. $send_url ="https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={$re_access_token}";
  546. $result = $this->sendhttps_post($send_url, json_encode($template));
  547. //log
  548. $ck_json_arr = json_decode($result,true);
  549. return $ck_json_arr;
  550. }
  551. /**
  552. 发送小程序模板消息
  553. **/
  554. function send_wxtemplate_msg($template_data,$url,$pagepath,$to_openid,$template_id,$form_id='1',$uniacid=0,$wx_template_data = array() ,$delay_time = 0)
  555. {
  556. $weixin_config = array();
  557. $weixin_config['appid'] = D('Seller/Front')->get_config_by_name('wepro_appid');
  558. $weixin_config['appscert'] = D('Seller/Front')->get_config_by_name('wepro_appsecret');
  559. $siteroot = D('Seller/Front')->get_config_by_name('shop_domain');
  560. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  561. $re_access_token = $jssdk->getweAccessToken();
  562. $template = array(
  563. 'touser' => $to_openid,
  564. 'template_id' => $template_id,
  565. 'form_id' => $form_id,
  566. 'page' => $pagepath,
  567. 'data' => $template_data
  568. );
  569. if(!empty($wx_template_data))
  570. {
  571. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token={$re_access_token}";
  572. $new_template = array();
  573. $new_template['touser'] = $to_openid;
  574. $new_template['mp_template_msg'] = array(
  575. 'appid' => $wx_template_data['appid'],
  576. 'template_id' => $wx_template_data['template_id'],
  577. 'url' => $siteroot,
  578. 'miniprogram' => array(
  579. 'appid' => $weixin_config['appid'],
  580. 'pagepath' => $wx_template_data['pagepath']
  581. ),
  582. 'data' => $wx_template_data['data']
  583. );
  584. $result = $this->sendhttps_post($url, json_encode($new_template));
  585. $result_arr = json_decode($result, true);
  586. if( $result_arr['errcode'] > 0 )
  587. {
  588. $new_template['mp_template_msg'] = array(
  589. 'appid' => $wx_template_data['appid'],
  590. 'template_id' => $wx_template_data['template_id'],
  591. 'url' => $siteroot,
  592. 'miniprogram' => array(
  593. 'appid' => $weixin_config['appid'],
  594. 'page' => $wx_template_data['pagepath']
  595. ),
  596. 'data' => $wx_template_data['data']
  597. );
  598. $result = $this->sendhttps_post($url, json_encode($new_template));
  599. }
  600. //$result = json_encode($result);
  601. }
  602. if( !empty($template_data) )
  603. {
  604. if($delay_time > 0)
  605. sleep($delay_time);
  606. $send_url ="https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={$re_access_token}";
  607. $result = $this->sendhttps_post($send_url, json_encode($template));
  608. }
  609. return json_decode($result,true);
  610. }
  611. function curl_datas($url,$data,$timeout=30)
  612. {
  613. $ch = curl_init();
  614. //取数据的地址
  615. curl_setopt($ch, CURLOPT_URL, $url);
  616. //传输为post
  617. if(defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
  618. curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  619. }
  620. curl_setopt($ch, CURLOPT_POST, true);
  621. //传输数据(这里data是二维数组,一定要加http_build_query,不然会报错)
  622. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  623. //隐藏返回结果
  624. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  625. //限制时间
  626. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  627. //https支持
  628. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
  629. //执行
  630. $handles = curl_exec($ch);
  631. //断开
  632. curl_close($ch);
  633. return $handles;
  634. }
  635. public function just_send_wxtemplate($to_openid, $uniacid=0,$wx_template_data = array() )
  636. {
  637. $weixin_config = array();
  638. $weixin_config['appid'] = D('Seller/Front')->get_config_by_name('wepro_appid');
  639. $weixin_config['appscert'] = D('Seller/Front')->get_config_by_name('wepro_appsecret');
  640. $siteroot = D('Seller/Front')->get_config_by_name('shop_domain');
  641. $jssdk = new \Lib\Weixin\Jssdk( $weixin_config['appid'], $weixin_config['appscert']);
  642. $re_access_token = $jssdk->getweAccessToken();
  643. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token={$re_access_token}";
  644. $new_template = array();
  645. $new_template['touser'] = $to_openid;
  646. $new_template['mp_template_msg'] = array(
  647. 'appid' => $wx_template_data['appid'],
  648. 'template_id' => $wx_template_data['template_id'],
  649. 'url' => $siteroot,
  650. 'miniprogram' => array(
  651. 'appid' => $weixin_config['appid'],
  652. 'pagepath' => $wx_template_data['pagepath']
  653. ),
  654. 'data' => $wx_template_data['data']
  655. );
  656. $result = $this->sendhttps_post($url, json_encode($new_template));
  657. }
  658. function sendhttp_get($url)
  659. {
  660. $curl = curl_init();
  661. curl_setopt($curl,CURLOPT_URL,$url);
  662. curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,FALSE);
  663. curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,FALSE);
  664. curl_setopt($curl,CURLOPT_POST,1);
  665. curl_setopt($curl,CURLOPT_POSTFIELDS,array());
  666. curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
  667. $result = curl_exec($curl);
  668. curl_close($curl);
  669. return $result;
  670. }
  671. function sendhttps_post($url,$data)
  672. {
  673. $curl = curl_init();
  674. curl_setopt($curl,CURLOPT_URL,$url);
  675. curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,FALSE);
  676. curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,FALSE);
  677. curl_setopt($curl,CURLOPT_POST,1);
  678. curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
  679. curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
  680. $result = curl_exec($curl);
  681. if(curl_errno($curl)){
  682. return 'Errno'.curl_error($curl);
  683. }
  684. curl_close($curl);
  685. return $result;
  686. }
  687. }
  688. ?>