管理员
   
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
5 H. C% h3 m2 c9 J1.添加商品信息+ y* R& h3 t% D! [2 n
2.添加图片
* z$ Y" W0 C2 }) o. ^; v3.查询所有产品
6 Z3 j D7 V4 Z/ Y# O5 j0 ~, @9 p4.查询某个具体产品信息) V6 T" a1 A4 \. w
5.删除某个产品# L) \3 ~6 R5 [8 v- P3 S8 D
6.删除图片
: F; }# d5 @: l8 M; y9 F7.图像识别
% Q' }& K+ E k( N, L$ j
9 T& i9 ]2 T' u/ E图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
8 o4 i* |& D( u; L! x; p9 O$ s' `3 C
PHP示例:
' ~5 a/ g; k$ ^$ A% N- <!--?php
U* O, _; g; [' J; y) \/ u& U - // +----------------------------------------------------------------------
% f B' n% L, j" C$ i" ~: | - // | JuhePHP [ NO ZUO NO DIE ], ~& g/ c) d1 K3 ]1 Z2 K3 f% v
- // +----------------------------------------------------------------------
! o* \6 M( F0 J) w: s' ]5 G3 g# Y - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved., A6 r& r; Y& j) p8 i& ?* |
- // +----------------------------------------------------------------------. r& K4 B5 H3 k% m/ {$ G, Y$ V
- // | Author: Juhedata <info@juhe.cn-->
# m. x% z7 F! u4 C2 }* r: D - // +----------------------------------------------------------------------
% C$ b H# g9 M# N) ?0 n - 2 o' g0 M, A% f6 V* \8 {& S! c% Q! g, O
- //----------------------------------# r1 N7 p8 `% L
- // 图像识别调用示例代码 - 聚合数据' g4 l9 g5 r. E0 M3 U; X2 r
- // 在线接口文档:http://www.juhe.cn/docs/117$ x* G2 a1 d e
- //----------------------------------
. d& p, F; s' n -
# G' m4 u- S$ d) g% T: h - header('Content-type:text/html;charset=utf-8'); M) P' o5 n9 z R) @$ h6 F8 K
-
% o# F8 i4 N6 b; q -
4 }- a& G: i, C& S1 v - //配置您申请的appkey8 R; l/ k& [' J
- $appkey = "*********************";' R- r5 _, A3 L) ?: p) b; I# J2 U
- , X% K* M1 p- n
- : s' s- s% d" D* z; O( V `6 D/ |
-
8 e+ p9 `# j# L. e' ^* d -
; T q* k% u- x - //************1.图像上传************
; y8 L* c4 p- A- a) t - $url = "http://japi.juhe.cn/image_recognition/upload";
( e/ N' ^7 U7 ^5 o - $params = array(
+ b7 M! G1 t9 G, d5 R - "file" => "",//上传的单张图片1 i, ?$ }! i% w( f. l# [! e
- "key" => $appkey,//APP Key
; j* h4 h3 Y' z& L) e2 h+ E - "pname" => "",//包名) _/ T- l& e+ i( {, E
- );! ?) @( c7 w: o( W6 P
- $paramstring = http_build_query($params);
; s) P0 b$ \/ d4 E- w; N/ R - $content = juhecurl($url,$paramstring,1);
% s! U2 s7 d& e# z5 n - $result = json_decode($content,true);
( Z" G# n: o! L9 | - if($result){7 v- f- r2 M' u
- if($result['error_code']=='0'){
2 p9 I+ u6 i) w+ o - print_r($result);
3 b$ B6 j! u, o: h7 R! f7 o/ S9 e - }else{8 d- S% ]' l* |+ z+ ^" M
- echo $result['error_code'].":".$result['reason'];
# J6 y7 ]' A% i/ J* q/ s8 Y0 [- } - }
- ~" D) G# J; T2 l- `( U0 i. t5 g - }else{
0 T% _! S' W! g; x - echo "请求失败";
5 r. \4 ~% {" n; w3 @ a1 O5 h2 Q - }
1 J3 a2 `( G4 e7 ]8 V - //**************************************************2 q0 D, p T% w2 Y# L$ E0 ^
- # |$ I. f- k' ^
- - _- q7 J9 N/ A: g
- : w c# s# s$ V! S$ N8 o ~* J
-
7 V) e' } i4 J! Q" f$ k - //************2.查寻上传图像信息************
5 t v/ `) m* @) ]6 f - $url = "http://japi.juhe.cn/image_recognition/findAll";
4 }) I+ j" L6 t* C/ G# Q0 D - $params = array(6 M: I* J) m, y4 A! I8 f4 Q
- "key" => $appkey,//APP Key$ ^. G& i( r$ w) n7 j: N
- );
( Z5 U. y. C- ~: y/ [ - $paramstring = http_build_query($params);
% d: I9 A$ _! @7 q a - $content = juhecurl($url,$paramstring);
0 x( g' H" v# S' `5 }. \ - $result = json_decode($content,true);
9 }' e7 P% z7 I( w" W) J+ P/ x - if($result){2 \9 ]1 ?7 P9 I f
- if($result['error_code']=='0'){
* a: |& m5 {( ?4 r. ?3 k2 A - print_r($result);
1 D8 W ]5 S9 ? - }else{& T0 g: m( l1 D& b% Q
- echo $result['error_code'].":".$result['reason'];* r7 H; D0 j+ X, {+ V
- }
, x% K) w6 R* a& a - }else{
/ k* P1 k$ ?/ Y: C - echo "请求失败";& l# T1 S3 B, i( f: P+ r* f6 Y
- }+ _5 [8 R. h1 L5 j( c
- //**************************************************7 N- k8 o- X% X( j- b( o: j
- H+ n0 E, X' r- h5 s
- 0 y m5 x3 d' _% q
- # `; t1 K0 M- O' H }+ Z3 Y
- - D( i. D5 b$ t g* T) K
- //************3.删除图像信息************. I$ J8 L, K0 l
- $url = "http://japi.juhe.cn/image_recognition/delete";% D- `0 Q A9 c+ z4 X8 l* i
- $params = array(
: h- t$ f# Q" d3 |' Q - "key" => $appkey,//APP Key
' V/ w0 G; m( T - "imageId" => "",//图片ID
1 B& b( m+ f1 H% l6 a1 E - );) S# `7 M3 F/ D: h/ w
- $paramstring = http_build_query($params);1 Q8 n0 V! Y. ? @/ y
- $content = juhecurl($url,$paramstring);% \* I# ~1 E3 Q: [& i% i* c0 U8 Z
- $result = json_decode($content,true);$ y& G" K/ t' O2 M
- if($result){. v7 H1 S& K5 w2 _6 I
- if($result['error_code']=='0'){
' ], i+ D* O( C - print_r($result);
4 ^- E) g2 ]/ P& f j. C - }else{
" ]& C' I3 t) B8 \/ d2 y - echo $result['error_code'].":".$result['reason'];
, E* h1 Z$ Z5 u) R' f - }
" o3 I# I* n( i2 K g1 ] - }else{# u' n) X, \" Z5 @5 v/ K
- echo "请求失败";! }+ @/ s6 d$ v; f3 ]5 @
- }) g7 }& t5 ^" y s8 b
- //**************************************************! R$ p: y. b$ Q% U! E
-
. O# [1 C% K2 a: C0 I: q1 h C5 t - - b. l1 g' ^" w; U+ i) k/ u" ]6 V
- : o, I. u9 t# x @+ O. s/ }/ @' L
- 1 v) {( l. H% X
- //************4.图像识别************
! ^3 z. p& a9 N% t, j2 p - $url = "http://japi.juhe.cn/image_recognition/check";# r$ P% v' n' R k
- $params = array(
1 K I- _% A3 k/ n6 z$ l6 A$ G/ L - "file" => "",//上传的图片
+ c) |9 Y- G2 t+ G& Y5 |! J - "key" => $appkey,//APP Key
$ t- d; h$ |0 {# \2 m: |2 a5 b - "pname" => "",//包名
/ y5 ?# M$ U/ U - "device_name" => "",//设备名称(如android OS或iphone OS)
& f: N; ?0 [. t1 r. u1 H - "device_version" => "",//设备版本(如:4.0.3)( |7 w, m; @ @/ D) B
- "latitude" => "",//纬度
; q; M' [, k0 w( @1 h5 h/ w; j* G - "longitude" => "",//经度$ C: Y6 J* R# b
- "uuid" => "",//设备id
7 _* G3 W$ t5 W$ h f @+ f - "zone" => "",//请求地区
% S6 l* Y2 a- s+ M# j- Q7 U+ X - );
" C4 p* T( \' W6 ] - $paramstring = http_build_query($params);
1 a1 Z* W* `$ z0 d8 U - $content = juhecurl($url,$paramstring,1);' h2 L( C) N( x0 H4 u) e8 X/ ?- q
- $result = json_decode($content,true);% J9 X; A* b, N# q W2 ]( y; T+ W1 i
- if($result){7 Z4 j3 _0 o+ q
- if($result['error_code']=='0'){
+ z0 r8 u+ V4 D& B" c* k$ Q$ F7 u - print_r($result);8 R; I2 z# z) U$ j' e
- }else{
! m) F6 f$ M$ f# J' g- N% S - echo $result['error_code'].":".$result['reason'];( F3 e. J; h( p& L! p
- }5 t! }/ U, A. e( D4 ^
- }else{8 _0 ~* n1 }7 W; M
- echo "请求失败";
) l! E* F4 M+ o' T - }, S. ?: g1 D' f) h
- //**************************************************& C% r- v1 x$ G" h+ w
-
" d5 m& f( O6 o; K- w8 ^0 W6 m -
* y: M( e9 k# M; X7 r' l d4 ~' l -
: e& J$ F+ L3 m! g: @* U) x) J - - h( U' D# e) n0 ]2 _7 X4 ?5 y: O& k
-
% s5 P. G- b/ z: A9 X - /**: z* ]1 R+ P7 B5 }1 N- [
- * 请求接口返回内容
* D% n/ l. J W7 p3 c& l0 g( ?# G - * @param string $url [请求的URL地址]
! G7 ]" t" ^$ c* x3 I9 M - * @param string $params [请求的参数]+ {, c+ s$ e7 }5 |5 _, }. u
- * @param int $ipost [是否采用POST形式]
( I* J! g g: @) c/ } - * @return string' Z7 }2 I" {! ^% P% B
- */
5 {- t0 M( q6 F' f8 \+ c - function juhecurl($url,$params=false,$ispost=0){. V# R O: A+ e, A! x! }# Z) x- U
- $httpInfo = array();: ~$ N/ A0 G P$ g3 E0 E0 t
- $ch = curl_init(); G& O! Y* R- Z9 v5 {& W
-
, T) I( B+ a; J, i* Q! c6 g - curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );0 v4 ]) U' C2 e j
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
, n( }1 p7 N" ~$ R# \' s - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
2 b0 u4 ?( f( N+ V - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
' U) U8 k9 @8 m2 ~( ?2 ? - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
/ J8 h5 I5 G: I4 o( j& R - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);. }& E: j9 ~7 }' |
- if( $ispost )) ^. Z. \. {. H9 h N
- {
x8 }0 V, J/ O ` s - curl_setopt( $ch , CURLOPT_POST , true );/ W) O3 I( n) i0 q/ j0 \, K- \
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
6 P0 k& D$ L# Z0 ]5 d4 F0 @7 q5 U - curl_setopt( $ch , CURLOPT_URL , $url );( e0 e- h. s+ h4 |) K
- }) a/ o7 Q& f) E2 v
- else- D8 M9 R5 F- X% V9 G9 M
- {
4 X" e0 t7 V8 c( ^/ I5 l1 {1 A$ b - if($params){
4 P5 ^: d! }, ~) q - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );+ {' |) b9 x4 M1 y. }; K
- }else{& y3 ]- }5 H: d
- curl_setopt( $ch , CURLOPT_URL , $url);
9 w4 A! U" u2 z \ {$ \ - }
& N: C. p' h' {4 E3 s+ l- p; N6 M% \ - }$ v" v5 S+ P" n; w% G7 b. N% D
- $response = curl_exec( $ch );5 h/ ^& R# H% y
- if ($response === FALSE) {" R A# g2 ~. N2 C* s
- //echo "cURL Error: " . curl_error($ch);1 r4 @/ ?5 N* j7 e8 C; y
- return false;
" R! |( V+ i2 s! J! B5 B$ m# t p - }
0 ^7 f: |3 b0 F$ A - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
* ]7 _5 C: e* ^/ s+ x - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
# ?$ F/ S2 ]' x. \1 i4 C; s* ^ - curl_close( $ch );
2 H4 |% O: Y) g$ S* }& \ - return $response;
+ q) d9 ]! i# s8 _! q+ x - }
复制代码
: n0 ^+ ~) r7 S% Y1 B9 T5 I& q+ w5 ~" u& f. p& p: N+ Y
|
|